home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / awt / Component.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  129.3 KB  |  4,108 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Component.java    1.223 98/09/15
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.io.PrintStream;
  17. import java.io.PrintWriter;
  18. import java.util.Vector;
  19. import java.util.Locale;
  20. import java.awt.peer.ComponentPeer;
  21. import java.awt.image.ImageObserver;
  22. import java.awt.image.ImageProducer;
  23. import java.awt.image.ColorModel;
  24. import java.awt.event.*;
  25. import java.awt.datatransfer.Transferable;
  26. import java.awt.dnd.DnDConstants;
  27. import java.awt.dnd.DragSource;
  28. import java.awt.dnd.DragSourceContext;
  29. import java.awt.dnd.DragSourceListener;
  30. import java.awt.dnd.InvalidDnDOperationException;
  31. import java.io.Serializable;
  32. import java.io.ObjectOutputStream;
  33. import java.io.ObjectInputStream;
  34. import java.io.IOException;
  35. import java.beans.PropertyChangeListener;
  36. import java.awt.event.InputMethodListener;
  37. import java.awt.event.InputMethodEvent;
  38. import java.awt.im.InputContext;
  39. import java.awt.im.InputMethodRequests;
  40. import java.awt.dnd.DropTarget;
  41.  
  42. import sun.security.action.GetPropertyAction;
  43. import sun.awt.AppContext;
  44. import sun.awt.SunToolkit;
  45. import sun.awt.ConstrainableGraphics;
  46.  
  47. /**
  48.  * A <em>component</em> is an object having a graphical representation
  49.  * that can be displayed on the screen and that can interact with the
  50.  * user. Examples of components are the buttons, checkboxes, and scrollbars
  51.  * of a typical graphical user interface. <p>
  52.  * The <code>Component</code> class is the abstract superclass of
  53.  * the nonmenu-related Abstract Window Toolkit components. Class
  54.  * <code>Component</code> can also be extended directly to create a
  55.  * lightweight component. A lightweight component is a component that is
  56.  * not associated with a native opaque window.
  57.  *
  58.  * @version     1.223, 09/15/98
  59.  * @author     Arthur van Hoff
  60.  * @author     Sami Shaio
  61.  */
  62. public abstract class Component implements ImageObserver, MenuContainer,
  63.     Serializable
  64. {
  65.     /**
  66.      * The peer of the component. The peer implements the component's
  67.      * behaviour. The peer is set when the Component is added to a
  68.      * container that also is a peer.
  69.      * @see #addNotify
  70.      * @see #removeNotify
  71.      */
  72.     transient ComponentPeer peer;
  73.  
  74.     /**
  75.      * The parent of the object. It may be null for top-level components.
  76.      * @see #getParent
  77.      */
  78.     transient Container parent;
  79.  
  80.     /**
  81.      * The AppContext of the component.  This is set in the constructor
  82.      * and never changes.
  83.      */
  84.     transient AppContext appContext;
  85.  
  86.     /**
  87.      * The x position of the component in the parent's coordinate system.
  88.      *
  89.      * @serial
  90.      * @see #getLocation
  91.      */
  92.     int x;
  93.  
  94.     /**
  95.      * The y position of the component in the parent's coordinate system.
  96.      *
  97.      * @serial
  98.      * @see #getLocation
  99.      */
  100.     int y;
  101.  
  102.     /**
  103.      * The width of the component.
  104.      *
  105.      * @serial
  106.      * @see #getSize
  107.      */
  108.     int width;
  109.  
  110.     /**
  111.      * The height of the component.
  112.      *
  113.      * @serial
  114.      * @see #getSize
  115.      */
  116.     int height;
  117.  
  118.     /**
  119.      * The foreground color for this component.
  120.      * foreground color can be null.
  121.      *
  122.      * @serial
  123.      * @see #getForeground
  124.      * @see #setForeground
  125.      */
  126.     Color    foreground;
  127.  
  128.     /**
  129.      * The background color for this component.
  130.      * background can be null.
  131.      *
  132.      * @serial
  133.      * @see #getBackground
  134.      * @see #setBackground
  135.      */
  136.     Color    background;
  137.  
  138.     /**
  139.      * The font used by this component.
  140.      * The font can be null.
  141.      *
  142.      * @serial
  143.      * @see #getFont
  144.      * @see #setFont
  145.      */
  146.     Font    font;
  147.  
  148.     /**
  149.      * The font which the peer is currently using. (null if no peer exists.)
  150.      */
  151.     Font        peerFont;
  152.  
  153.     /**
  154.      * The cursor displayed when pointer is over this component.
  155.      * cursor must always be a non-null cursor image.
  156.      *
  157.      * @serial
  158.      * @see #getCursor
  159.      * @see #setCursor
  160.      */
  161.     Cursor    cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
  162.  
  163.     /**
  164.      * The locale for the component.
  165.      *
  166.      * @serial
  167.      * @see #getLocale
  168.      * @see #setLocale
  169.      */
  170.     Locale      locale;
  171.  
  172.     /**
  173.      * True when the object is visible. An object that is not
  174.      * visible is not drawn on the screen.
  175.      *
  176.      * @serial
  177.      * @see #isVisible
  178.      * @see #setVisible
  179.      */
  180.     boolean visible = true;
  181.  
  182.     /**
  183.      * True when the object is enabled. An object that is not
  184.      * enabled does not interact with the user.
  185.      *
  186.      * @serial
  187.      * @see #isEnabled
  188.      * @see #setEnabled
  189.      */
  190.     boolean enabled = true;
  191.  
  192.     /**
  193.      * True when the object is valid. An invalid object needs to
  194.      * be layed out. This flag is set to false when the object
  195.      * size is changed.
  196.      *
  197.      * @serial
  198.      * @see #isValid
  199.      * @see #validate
  200.      * @see #invalidate
  201.      */
  202.     boolean valid = false;
  203.  
  204.     /**
  205.      * The DropTarget associated with this Component.
  206.      *
  207.      * @since JDK 1.2
  208.      * @serial 
  209.      * @see #setDropTarget
  210.      * @see #getDropTarget
  211.      */
  212.     DropTarget dropTarget;
  213.  
  214.  
  215.     /**
  216.      * True if this component has enabled focus events and currently
  217.      * has the focus.
  218.      *
  219.      * @serial
  220.      * @see #hasFocus
  221.      * @see #processFocusEvent
  222.      */
  223.     boolean hasFocus = false;
  224.  
  225.     /**
  226.      * @serial
  227.      * @see add()
  228.      */
  229.     Vector popups;
  230.  
  231.     /**
  232.      * A components name.
  233.      * This field can be null.
  234.      *
  235.      * @serial
  236.      * @see getName()
  237.      * @see setName()
  238.      */
  239.     private String name;
  240.   
  241.     /**
  242.      * A bool to determine whether the name has
  243.      * been set explicitly. nameExplicitlySet will
  244.      * be false if the name has not been set and
  245.      * true if it has.
  246.      *
  247.      * @serial
  248.      * @see getName()
  249.      * @see setName()
  250.      */
  251.     private boolean nameExplicitlySet = false;
  252.  
  253.     /**
  254.      * The locking object for AWT component-tree and layout operations.
  255.      *
  256.      * @see #getTreeLock
  257.      */
  258.     static final Object LOCK = new AWTTreeLock();
  259.     static class AWTTreeLock {}
  260.  
  261.     /**
  262.      * Internal, cached size information.
  263.      * (This field perhaps should have been transient).
  264.      *
  265.      * @serial
  266.      */
  267.     Dimension minSize;
  268.  
  269.     /** Internal, cached size information
  270.      * (This field perhaps should have been transient).
  271.      *
  272.      * @serial
  273.      */
  274.     Dimension prefSize;
  275.  
  276.     /**
  277.      * The orientation for this component.
  278.      * @see #getComponentOrientation
  279.      * @see #setComponentOrientation(java.awt.ComponentOrientation)
  280.      */
  281.     transient ComponentOrientation componentOrientation
  282.                 = ComponentOrientation.UNKNOWN;
  283.  
  284.     /**
  285.      * newEventsOnly will be true if the event is
  286.      * one of the event types enabled for the component.
  287.      * It will then allow for normal processing to
  288.      * continue.  If it is false the event is passed
  289.      * to the components parent and up the ancestor
  290.      * tree until the event has been consumed.
  291.      *
  292.      * @serial
  293.      * @see dispatchEvent()
  294.      */
  295.     boolean newEventsOnly = false;
  296.     transient ComponentListener componentListener;
  297.     transient FocusListener focusListener;
  298.     transient KeyListener keyListener;
  299.     transient MouseListener mouseListener;
  300.     transient MouseMotionListener mouseMotionListener;
  301.     transient InputMethodListener inputMethodListener;
  302.  
  303.     /** Internal, constants for serialization */
  304.     final static String actionListenerK = "actionL";
  305.     final static String adjustmentListenerK = "adjustmentL";
  306.     final static String componentListenerK = "componentL";
  307.     final static String containerListenerK = "containerL";
  308.     final static String focusListenerK = "focusL";
  309.     final static String itemListenerK = "itemL";
  310.     final static String keyListenerK = "keyL";
  311.     final static String mouseListenerK = "mouseL";
  312.     final static String mouseMotionListenerK = "mouseMotionL";
  313.     final static String textListenerK = "textL";
  314.     final static String ownedWindowK = "ownedL";
  315.     final static String windowListenerK = "windowL";
  316.     final static String inputMethodListenerK = "inputMethodL";
  317.  
  318.     /**
  319.      * The eventMask is ONLY set by subclasses via enableEvents.
  320.      * The mask should NOT be set when listeners are registered
  321.      * so that we can distinguish the difference between when
  322.      * listeners request events and subclasses request them.
  323.      * One bit is used to indicate whether input methods are
  324.      * enabled; this bit is set by enableInputMethods and is
  325.      * on by default.
  326.      *
  327.      * @serial
  328.      * @see enableInputMethods()
  329.      */
  330.     long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;
  331.  
  332.     // enable for assertion checking
  333.     private final static boolean assert = false;
  334.  
  335.     /**
  336.      * Static properties for incremental drawing.
  337.      * @see #imageUpdate
  338.      */
  339.     static boolean isInc;
  340.     static int incRate;
  341.     static {
  342.         /* ensure that the necessary native libraries are loaded */
  343.     Toolkit.loadLibraries();
  344.     /* initialize JNI field and method ids */
  345.     initIDs();
  346.  
  347.     String s = (String) java.security.AccessController.doPrivileged(
  348.                new GetPropertyAction("awt.image.incrementaldraw"));
  349.     isInc = (s == null || s.equals("true"));
  350.  
  351.     s = (String) java.security.AccessController.doPrivileged(
  352.                new GetPropertyAction("awt.image.redrawrate"));
  353.     incRate = (s != null) ? Integer.parseInt(s) : 100;
  354.     }
  355.  
  356.     /**
  357.      * Ease-of-use constant for <code>getAlignmentY()</code>.  Specifies an
  358.      * alignment to the top of the component.
  359.      * @see     #getAlignmentY
  360.      */
  361.     public static final float TOP_ALIGNMENT = 0.0f;
  362.  
  363.     /**
  364.      * Ease-of-use constant for <code>getAlignmentY</code> and
  365.      * <code>getAlignmentX</code>. Specifies an alignment to
  366.      * the center of the component
  367.      * @see     #getAlignmentX
  368.      * @see     #getAlignmentY
  369.      */
  370.     public static final float CENTER_ALIGNMENT = 0.5f;
  371.  
  372.     /**
  373.      * Ease-of-use constant for <code>getAlignmentY</code>.  Specifies an
  374.      * alignment to the bottom of the component.
  375.      * @see     #getAlignmentY
  376.      */
  377.     public static final float BOTTOM_ALIGNMENT = 1.0f;
  378.  
  379.     /**
  380.      * Ease-of-use constant for <code>getAlignmentX</code>.  Specifies an
  381.      * alignment to the left side of the component.
  382.      * @see     #getAlignmentX
  383.      */
  384.     public static final float LEFT_ALIGNMENT = 0.0f;
  385.  
  386.     /**
  387.      * Ease-of-use constant for <code>getAlignmentX</code>.  Specifies an
  388.      * alignment to the right side of the component.
  389.      * @see     #getAlignmentX
  390.      */
  391.     public static final float RIGHT_ALIGNMENT = 1.0f;
  392.  
  393.     /*
  394.      * JDK 1.1 serialVersionUID
  395.      */
  396.     private static final long serialVersionUID = -7644114512714619750L;
  397.  
  398.     /**
  399.      * If any PropertyChangeListeners have been registered, the
  400.      * changeSupport field describes them.
  401.      *
  402.      * @serial
  403.      * @since JDK 1.2
  404.      * @see addPropertyChangeListener()
  405.      * @see removePropertyChangeListener()
  406.      * @see firePropertyChange()
  407.      */
  408.     private java.beans.PropertyChangeSupport changeSupport;
  409.  
  410.     boolean isPacked = false;
  411.  
  412.     /**
  413.      * Constructs a new component. Class <code>Component</code> can be
  414.      * extended directly to create a lightweight component that does not
  415.      * utilize an opaque native window. A lightweight component must be
  416.      * hosted by a native container somewhere higher up in the component
  417.      * tree (for example, by a <code>Frame</code> object).
  418.      */
  419.     protected Component() {
  420.     appContext = AppContext.getAppContext();
  421.     SunToolkit.insertTargetMapping(this, appContext);
  422.     }
  423.  
  424.     /**
  425.      * Construct a name for this component.  Called by getName() when the
  426.      * name is null.
  427.      */
  428.     String constructComponentName() {
  429.         return null; // For strict compliance with prior JDKs, a Component
  430.                      // that doesn't set its name should return null from
  431.                      // getName()
  432.     }
  433.  
  434.     /**
  435.      * Gets the name of the component.
  436.      * @return This component's name.
  437.      * @see    #setName
  438.      * @since JDK1.1
  439.      */
  440.     public String getName() {
  441.         if (name == null && !nameExplicitlySet) {
  442.             synchronized(this) {
  443.                 if (name == null && !nameExplicitlySet)
  444.                     name = constructComponentName();
  445.             }
  446.         }
  447.         return name;
  448.     }
  449.  
  450.     /**
  451.      * Sets the name of the component to the specified string.
  452.      * @param name  The string that is to be this 
  453.      * component's name.
  454.      * @see #getName
  455.      * @since JDK1.1
  456.      */
  457.     public void setName(String name) {
  458.         synchronized(this) {
  459.             this.name = name;
  460.             nameExplicitlySet = true;
  461.         }
  462.     }
  463.  
  464.     /**
  465.      * Gets the parent of this component.
  466.      * @return The parent container of this component.
  467.      * @since JDK1.0
  468.      */
  469.     public Container getParent() {
  470.     return getParent_NoClientCode();
  471.     }
  472.  
  473.     // NOTE: This method may be called by privileged threads.
  474.     //       This functionality is implemented in a package-private method 
  475.     //       to insure that it cannot be overridden by client subclasses. 
  476.     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  477.     final Container getParent_NoClientCode() {
  478.     return parent;
  479.     }
  480.  
  481.     /**
  482.      * @deprecated As of JDK version 1.1,
  483.      * programs should not directly manipulate peers.
  484.      * replaced by <code>boolean isDisplayable()</code>.
  485.      */
  486.     public ComponentPeer getPeer() {
  487.     return peer;
  488.     }
  489.  
  490.     /**
  491.      * Associate a DropTarget with this Component.
  492.      *
  493.      * @param dt The DropTarget
  494.      *
  495.      * @throw SecurityException
  496.      * @throw IllegalArgumentException
  497.      * @throw UnsupportedOperationException
  498.      */
  499.  
  500.     public synchronized void setDropTarget(DropTarget dt) {
  501.     if (dt == dropTarget || (dropTarget != null && dropTarget.equals(dt)))
  502.         return;
  503.  
  504.     DropTarget old;
  505.  
  506.     if ((old = dropTarget) != null) {
  507.         if (peer != null) dropTarget.removeNotify(peer);
  508.  
  509.         DropTarget t = dropTarget;
  510.  
  511.         dropTarget = null;
  512.  
  513.         try {
  514.             t.setComponent(null);
  515.         } catch (IllegalArgumentException iae) {
  516.         // ignore it.
  517.         }
  518.     }
  519.  
  520.     // if we have a new one, and we have a peer, add it!
  521.  
  522.     if ((dropTarget = dt) != null) {
  523.         try {
  524.             dropTarget.setComponent(this);
  525.             if (peer != null) dropTarget.addNotify(peer);
  526.         } catch (IllegalArgumentException iae) {
  527.         if (old != null) {
  528.             try {
  529.                 old.setComponent(this);
  530.                 if (peer != null) dropTarget.addNotify(peer);
  531.             } catch (IllegalArgumentException iae1) {
  532.             // ignore it!
  533.             }
  534.         }
  535.         }
  536.     }
  537.     }
  538.  
  539.     /**
  540.      * Get the DropTarget associated with this Component
  541.      */
  542.  
  543.     public synchronized DropTarget getDropTarget() { return dropTarget; }
  544.  
  545.     /**
  546.      * Gets the locking object for AWT component-tree and layout
  547.      * Gets this component's locking object (the object that owns the thread
  548.      * sychronization monitor) for AWT component-tree and layout
  549.      * operations.
  550.      * @return This component's locking object.
  551.      */
  552.     public final Object getTreeLock() {
  553.     return LOCK;
  554.     }
  555.  
  556.     /**
  557.      * Gets the toolkit of this component. Note that
  558.      * the frame that contains a component controls which
  559.      * toolkit is used by that component. Therefore if the component
  560.      * is moved from one frame to another, the toolkit it uses may change.
  561.      * @return  The toolkit of this component.
  562.      * @since JDK1.0
  563.      */
  564.     public Toolkit getToolkit() {
  565.     return getToolkitImpl();
  566.     }
  567.  
  568.     /*
  569.      * This is called by the native code, so client code can't
  570.      * be called on the toolkit thread.
  571.      */
  572.     final Toolkit getToolkitImpl() {
  573.           ComponentPeer peer = this.peer;
  574.      if ((peer != null) && ! (peer instanceof java.awt.peer.LightweightPeer)){
  575.         return peer.getToolkit();
  576.     }
  577.     Container parent = this.parent;
  578.     if (parent != null) {
  579.         return parent.getToolkitImpl();
  580.     }
  581.     return Toolkit.getDefaultToolkit();
  582.     }
  583.  
  584.     /**
  585.      * Determines whether this component is valid. A component is valid
  586.      * when it is correctly sized and positioned within its parent
  587.      * container and all its children are also valid. Components are
  588.      * invalidated when they are first shown on the screen.
  589.      * @return <code>true</code> if the component is valid; <code>false</code>
  590.      * otherwise.
  591.      * @see #validate
  592.      * @see #invalidate
  593.      * @since JDK1.0
  594.      */
  595.     public boolean isValid() {
  596.     return (peer != null) && valid;
  597.     }
  598.  
  599.     /**
  600.      * Determines whether this component is displayable. A component is 
  601.      * displayable when it is connected to a native screen resource.
  602.      * <p>
  603.      * A component is made displayable either when it is added to
  604.      * a displayable containment hierarchy or when its containment
  605.      * hierarchy is made displayable.
  606.      * A containment hierarchy is made displayable when its ancestor 
  607.      * window is either packed or made visible.
  608.      * <p>
  609.      * A component is made undisplayable either when it is removed from
  610.      * a displayable containment hierarchy or when its containment hierarchy
  611.      * is made undisplayable.  A containment hierarchy is made 
  612.      * undisplayable when its ancestor window is disposed.
  613.      *
  614.      * @return <code>true</code> if the component is displayable; 
  615.      * <code>false</code> otherwise.
  616.      * @see java.awt.Container#add(java.awt.Component)
  617.      * @see java.awt.Window#pack
  618.      * @see java.awt.Window#show
  619.      * @see java.awt.Container#remove(java.awt.Component)
  620.      * @see java.awt.Window#dispose
  621.      * @since JDK1.2
  622.      */
  623.     public boolean isDisplayable() {
  624.     return getPeer() != null;
  625.     }
  626.  
  627.     /**
  628.      * Determines whether this component should be visible when its
  629.      * parent is visible. Components are 
  630.      * initially visible, with the exception of top level components such 
  631.      * as <code>Frame</code> objects.
  632.      * @return <code>true</code> if the component is visible;
  633.      * <code>false</code> otherwise.
  634.      * @see #setVisible
  635.      * @since JDK1.0
  636.      */
  637.     public boolean isVisible() {
  638.     return visible;
  639.     }
  640.  
  641.     /**
  642.      * Determines whether this component is showing on screen. This means
  643.      * that the component must be visible, and it must be in a container
  644.      * that is visible and showing.
  645.      * @return <code>true</code> if the component is showing;
  646.      * <code>false</code> otherwise.
  647.      * @see #setVisible
  648.      * @since JDK1.0
  649.      */
  650.     public boolean isShowing() {
  651.     if (visible && (peer != null)) {
  652.             Container parent = this.parent;
  653.         return (parent == null) || parent.isShowing();
  654.     }
  655.     return false;
  656.     }
  657.  
  658.     /**
  659.      * Determines whether this component is enabled. An enabled component
  660.      * can respond to user input and generate events. Components are
  661.      * enabled initially by default. A component may be enabled or disabled by
  662.      * calling its <code>setEnabled</code> method.
  663.      * @return <code>true</code> if the component is enabled;
  664.      * <code>false</code> otherwise.
  665.      * @see #setEnabled
  666.      * @since JDK1.0
  667.      */
  668.     public boolean isEnabled() {
  669.     return isEnabledImpl();
  670.     }
  671.  
  672.     /*
  673.      * This is called by the native code, so client code can't
  674.      * be called on the toolkit thread.
  675.      */
  676.     final boolean isEnabledImpl() {
  677.     return enabled;
  678.     }
  679.  
  680.     /**
  681.      * Enables or disables this component, depending on the value of the
  682.      * parameter <code>b</code>. An enabled component can respond to user
  683.      * input and generate events. Components are enabled initially by default.
  684.      * @param     b   If <code>true</code>, this component is 
  685.      *            enabled; otherwise this component is disabled.
  686.      * @see #isEnabled
  687.      * @since JDK1.1
  688.      */
  689.     public void setEnabled(boolean b) {
  690.         enable(b);
  691.     }
  692.  
  693.     /**
  694.      * @deprecated As of JDK version 1.1,
  695.      * replaced by <code>setEnabled(boolean)</code>.
  696.      */
  697.     public void enable() {
  698.         if (enabled != true) {
  699.         synchronized (getTreeLock()) {
  700.         enabled = true;
  701.         ComponentPeer peer = this.peer;
  702.         if (peer != null) {
  703.             peer.enable();
  704.         }
  705.         }
  706.     }
  707.     }
  708.  
  709.     /**
  710.      * @deprecated As of JDK version 1.1,
  711.      * replaced by <code>setEnabled(boolean)</code>.
  712.      */
  713.     public void enable(boolean b) {
  714.     if (b) {
  715.         enable();
  716.     } else {
  717.         disable();
  718.     }
  719.     }
  720.  
  721.     /**
  722.      * @deprecated As of JDK version 1.1,
  723.      * replaced by <code>setEnabled(boolean)</code>.
  724.      */
  725.     public void disable() {
  726.         if (enabled != false) {
  727.         synchronized (getTreeLock()) {
  728.         enabled = false;
  729.         ComponentPeer peer = this.peer;
  730.         if (peer != null) {
  731.             peer.disable();
  732.         }
  733.         }
  734.     }
  735.     }
  736.  
  737.     /**
  738.      * Returns true if this component is painted to an offscreen image
  739.      * ("buffer") that's copied to the screen later.  Component
  740.      * subclasses that support double buffering should override this
  741.      * method to return true if double buffering is enabled.
  742.      * 
  743.      * @return false by default
  744.      */
  745.     public boolean isDoubleBuffered() {
  746.         return false;
  747.     }
  748.  
  749.     /**
  750.      * Enables or disables input method support for this component. If input
  751.      * method support is enabled and the component also processes key events,
  752.      * incoming events are offered to
  753.      * the current input method and will only be processed by the component or
  754.      * dispatched to its listeners if the input method does not consume them.
  755.      * By default, input method support is enabled.
  756.      *
  757.      * @param enable true to enable, false to disable.
  758.      * @see java.awt.Component#processKeyEvent
  759.      * @since JDK1.2
  760.      */
  761.     public void enableInputMethods(boolean enable) {
  762.         if (enable) {
  763.         if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0)
  764.         return;
  765.  
  766.         // If this component already has focus, then activate the
  767.         // input method by dispatching a synthesized focus gained
  768.         // event.
  769.         if (hasFocus() == true) {
  770.         InputContext inputContext = getInputContext();
  771.         if (inputContext != null) {
  772.             FocusEvent focusGainedEvent = new FocusEvent(this,
  773.                              FocusEvent.FOCUS_GAINED);
  774.             inputContext.dispatchEvent(focusGainedEvent);
  775.         }
  776.         }
  777.  
  778.             eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK;
  779.         } else {
  780.         if (areInputMethodsEnabled()) {
  781.         InputContext inputContext = getInputContext();
  782.         if (inputContext != null) {
  783.             inputContext.endComposition();
  784.             inputContext.removeNotify(this);
  785.         }
  786.         }
  787.             eventMask &= ~AWTEvent.INPUT_METHODS_ENABLED_MASK;
  788.         }
  789.     }
  790.  
  791.     /**
  792.      * Shows or hides this component depending on the value of parameter
  793.      * <code>b</code>.
  794.      * @param b  If <code>true</code>, shows this component; 
  795.      * otherwise, hides this component.
  796.      * @see #isVisible
  797.      * @since JDK1.1
  798.      */
  799.     public void setVisible(boolean b) {
  800.         show(b);
  801.     }
  802.  
  803.     /**
  804.      * @deprecated As of JDK version 1.1,
  805.      * replaced by <code>setVisible(boolean)</code>.
  806.      */
  807.     public void show() {
  808.     if (visible != true) {
  809.         synchronized (getTreeLock()) {
  810.         visible = true;
  811.                 ComponentPeer peer = this.peer;
  812.         if (peer != null) {
  813.             peer.show();
  814.             if (peer instanceof java.awt.peer.LightweightPeer) {
  815.             repaint();
  816.             }
  817.         }
  818.                 if (componentListener != null ||
  819.                     (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {
  820.                     ComponentEvent e = new ComponentEvent(this,
  821.                                      ComponentEvent.COMPONENT_SHOWN);
  822.                     Toolkit.getEventQueue().postEvent(e);
  823.                 }
  824.         }
  825.             Container parent = this.parent;
  826.         if (parent != null) {
  827.         parent.invalidate();
  828.         }
  829.     }
  830.     }
  831.  
  832.     /**
  833.      * @deprecated As of JDK version 1.1,
  834.      * replaced by <code>setVisible(boolean)</code>.
  835.      */
  836.     public void show(boolean b) {
  837.     if (b) {
  838.         show();
  839.     } else {
  840.         hide();
  841.     }
  842.     }
  843.  
  844.     /**
  845.      * @deprecated As of JDK version 1.1,
  846.      * replaced by <code>setVisible(boolean)</code>.
  847.      */
  848.     public void hide() {
  849.     if (visible != false) {
  850.         synchronized (getTreeLock()) {
  851.         visible = false;
  852.                 ComponentPeer peer = this.peer;
  853.         if (peer != null) {
  854.             peer.hide();
  855.             if (peer instanceof java.awt.peer.LightweightPeer) {
  856.             repaint();
  857.             }
  858.         }
  859.                 if (componentListener != null ||
  860.                     (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {
  861.                     ComponentEvent e = new ComponentEvent(this,
  862.                                      ComponentEvent.COMPONENT_HIDDEN);
  863.                     Toolkit.getEventQueue().postEvent(e);
  864.                 }
  865.         }
  866.             Container parent = this.parent;
  867.         if (parent != null) {
  868.         parent.invalidate();
  869.         }
  870.     }
  871.     }
  872.  
  873.     /**
  874.      * Gets the foreground color of this component.
  875.      * @return This component's foreground color. If this component does
  876.      * not have a foreground color, the foreground color of its parent
  877.      * is returned.
  878.      * @see #java.awt.Component#setForeground(java.awt.Color)
  879.      * @since JDK1.0
  880.      */
  881.     public Color getForeground() {
  882.           Color foreground = this.foreground;
  883.     if (foreground != null) {
  884.         return foreground;
  885.     }
  886.         Container parent = this.parent;
  887.     return (parent != null) ? parent.getForeground() : null;
  888.     }
  889.  
  890.     /**
  891.      * Sets the foreground color of this component.
  892.      * @param c The color to become this component's 
  893.      * foreground color.
  894.      * If this parameter is null then this component will inherit
  895.      * the foreground color of its parent.
  896.      * @see #getForeground
  897.      * @since JDK1.0
  898.      */
  899.     public void setForeground(Color c) {
  900.     Color oldColor = foreground;
  901.     ComponentPeer peer = this.peer;
  902.     foreground = c;
  903.     if (peer != null) {
  904.         c = getForeground();
  905.         if (c != null) {
  906.         peer.setForeground(c);
  907.         }
  908.     }
  909.     // This is a bound property, so report the change to
  910.     // any registered listeners.  (Cheap if there are none.)
  911.     firePropertyChange("foreground", oldColor, c);
  912.     }
  913.  
  914.     /**
  915.      * Gets the background color of this component.
  916.      * @return This component's background color. If this component does
  917.      * not have a background color, the background color of its parent
  918.      * is returned.
  919.      * @see java.awt.Component#setBackground(java.awt.Color)
  920.      * @since JDK1.0
  921.      */
  922.     public Color getBackground() {
  923.         Color background = this.background;
  924.     if (background != null) {
  925.         return background;
  926.     }
  927.         Container parent = this.parent;
  928.     return (parent != null) ? parent.getBackground() : null;
  929.     }
  930.  
  931.     /**
  932.      * Sets the background color of this component.
  933.      * @param c The color to become this component's color.
  934.      *        If this parameter is null then this component will inherit
  935.      *        the background color of its parent.
  936.      * background color.
  937.      * @see #getBackground
  938.      * @since JDK1.0
  939.      */
  940.     public void setBackground(Color c) {
  941.     Color oldColor = background;
  942.     ComponentPeer peer = this.peer;
  943.     background = c;
  944.     if (peer != null) {
  945.         c = getBackground();
  946.         if (c != null) {
  947.         peer.setBackground(c);
  948.         }
  949.     }
  950.     // This is a bound property, so report the change to
  951.     // any registered listeners.  (Cheap if there are none.)
  952.     firePropertyChange("background", oldColor, c);
  953.     }
  954.  
  955.     /**
  956.      * Gets the font of this component.
  957.      * @return This component's font. If a font has not been set
  958.      * for this component, the font of its parent is returned.
  959.      * @see #setFont
  960.      * @since JDK1.0
  961.      */
  962.     public Font getFont() {
  963.         Font font = this.font;
  964.     if (font != null) {
  965.         return font;
  966.     }
  967.         Container parent = this.parent;
  968.     return (parent != null) ? parent.getFont() : null;
  969.     }
  970.  
  971.     // NOTE: This method may be called by privileged threads.
  972.     //       This functionality is implemented in a package-private method 
  973.     //       to insure that it cannot be overridden by client subclasses. 
  974.     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  975.     final Font getFont_NoClientCode() {
  976.         Font font = this.font;
  977.     if (font != null) {
  978.         return font;
  979.     }
  980.         Container parent = this.parent;
  981.     return (parent != null) ? parent.getFont_NoClientCode() : null;
  982.     }
  983.  
  984.     /**
  985.      * Sets the font of this component.
  986.      * @param f The font to become this component's font.
  987.      * If this parameter is null then this component will inherit
  988.      * the font of its parent.
  989.      * @see #getFont
  990.      * @since JDK1.0
  991.      */
  992.     public void setFont(Font f) {
  993.     synchronized (this) {
  994.         Font oldFont = font;
  995.         ComponentPeer peer = this.peer;
  996.         font = f;
  997.         if (peer != null) {
  998.             f = getFont();
  999.         if (f != null) {
  1000.             peer.setFont(f);
  1001.             peerFont = f;
  1002.         }
  1003.         }
  1004.         // This is a bound property, so report the change to
  1005.         // any registered listeners.  (Cheap if there are none.)
  1006.         firePropertyChange("font", oldFont, font);
  1007.     }
  1008.  
  1009.     // This could change the preferred size of the Component.
  1010.     if (valid) {
  1011.         invalidate();
  1012.     }
  1013.     }
  1014.  
  1015.     /**
  1016.      * Gets the locale of this component.
  1017.      * @return This component's locale. If this component does not
  1018.      * have a locale, the locale of its parent is returned.
  1019.      * @see #setLocale
  1020.      * @exception IllegalComponentStateException If the Component
  1021.      * does not have its own locale and has not yet been added to
  1022.      * a containment hierarchy such that the locale can be determined
  1023.      * from the containing parent.
  1024.      * @since  JDK1.1
  1025.      */
  1026.     public Locale getLocale() {
  1027.         Locale locale = this.locale;
  1028.     if (locale != null) {
  1029.       return locale;
  1030.     }
  1031.         Container parent = this.parent;
  1032.  
  1033.     if (parent == null) {
  1034.         throw new IllegalComponentStateException("This component must have a parent in order to determine its locale");
  1035.     } else {
  1036.         return parent.getLocale();
  1037.     }
  1038.     }
  1039.  
  1040.     /**
  1041.      * Sets the locale of this component.
  1042.      * @param l The locale to become this component's locale.
  1043.      * @see #getLocale
  1044.      * @since JDK1.1
  1045.      */
  1046.     public void setLocale(Locale l) {
  1047.     locale = l;
  1048.  
  1049.     // This could change the preferred size of the Component.
  1050.     if (valid) {
  1051.         invalidate();
  1052.     }
  1053.     }
  1054.  
  1055.     /**
  1056.      * Gets the instance of <code>ColorModel</code> used to display
  1057.      * the component on the output device.
  1058.      * @return The color model used by this component.
  1059.      * @see java.awt.image.ColorModel
  1060.      * @see java.awt.peer.ComponentPeer#getColorModel()
  1061.      * @see java.awt.Toolkit#getColorModel()
  1062.      * @since JDK1.0
  1063.      */
  1064.     public ColorModel getColorModel() {
  1065.         ComponentPeer peer = this.peer;
  1066.     if ((peer != null) && ! (peer instanceof java.awt.peer.LightweightPeer)) {
  1067.         return peer.getColorModel();
  1068.     }
  1069.     return getToolkit().getColorModel();
  1070.     }
  1071.  
  1072.     /**
  1073.      * Gets the location of this component in the form of a
  1074.      * point specifying the component's top-left corner.
  1075.      * The location will be relative to the parent's coordinate space.
  1076.      * @return An instance of <code>Point</code> representing
  1077.      * the top-left corner of the component's bounds in the coordinate
  1078.      * space of the component's parent.
  1079.      * @see #setLocation
  1080.      * @see #getLocationOnScreen
  1081.      * @since JDK1.1
  1082.      */
  1083.     public Point getLocation() {
  1084.     return location();
  1085.     }
  1086.  
  1087.     /**
  1088.      * Gets the location of this component in the form of a point
  1089.      * specifying the component's top-left corner in the screen's
  1090.      * coordinate space.
  1091.      * @return An instance of <code>Point</code> representing
  1092.      * the top-left corner of the component's bounds in the
  1093.      * coordinate space of the screen.
  1094.      * @see #setLocation
  1095.      * @see #getLocation
  1096.      */
  1097.     public Point getLocationOnScreen() {
  1098.     synchronized (getTreeLock()) {
  1099.         if (peer != null && isShowing()) {
  1100.         if (peer instanceof java.awt.peer.LightweightPeer) {
  1101.             // lightweight component location needs to be translated
  1102.             // relative to a native component.
  1103.             Container host = getNativeContainer();
  1104.             Point pt = host.peer.getLocationOnScreen();
  1105.             for(Component c = this; c != host; c = c.getParent()) {
  1106.             pt.x += c.x;
  1107.             pt.y += c.y;
  1108.             }
  1109.             return pt;
  1110.         } else {
  1111.             Point pt = peer.getLocationOnScreen();
  1112.             return pt;
  1113.         }
  1114.         } else {
  1115.             throw new IllegalComponentStateException("component must be showing on the screen to determine its location");
  1116.         }
  1117.     }
  1118.     }
  1119.  
  1120.  
  1121.     /**
  1122.      * @deprecated As of JDK version 1.1,
  1123.      * replaced by <code>getLocation()</code>.
  1124.      */
  1125.     public Point location() {
  1126.     return new Point(x, y);
  1127.     }
  1128.  
  1129.     /**
  1130.      * Moves this component to a new location. The top-left corner of
  1131.      * the new location is specified by the <code>x</code> and <code>y</code>
  1132.      * parameters in the coordinate space of this component's parent.
  1133.      * @param x The <i>x</i>-coordinate of the new location's 
  1134.      * top-left corner in the parent's coordinate space.
  1135.      * @param y The <i>y</i>-coordinate of the new location's 
  1136.      * top-left corner in the parent's coordinate space.
  1137.      * @see #getLocation
  1138.      * @see #setBounds
  1139.      * @since JDK1.1
  1140.      */
  1141.     public void setLocation(int x, int y) {
  1142.     move(x, y);
  1143.     }
  1144.  
  1145.     /**
  1146.      * @deprecated As of JDK version 1.1,
  1147.      * replaced by <code>setLocation(int, int)</code>.
  1148.      */
  1149.     public void move(int x, int y) {
  1150.     setBounds(x, y, width, height);
  1151.     }
  1152.  
  1153.     /**
  1154.      * Moves this component to a new location. The top-left corner of
  1155.      * the new location is specified by point <code>p</code>. Point
  1156.      * <code>p</code> is given in the parent's coordinate space.
  1157.      * @param p The point defining the top-left corner 
  1158.      * of the new location, given in the coordinate space of this 
  1159.      * component's parent.
  1160.      * @see #getLocation
  1161.      * @see #setBounds
  1162.      * @since JDK1.1
  1163.      */
  1164.     public void setLocation(Point p) {
  1165.         setLocation(p.x, p.y);
  1166.     }
  1167.  
  1168.     /**
  1169.      * Returns the size of this component in the form of a
  1170.      * <code>Dimension</code> object. The <code>height</code>
  1171.      * field of the <code>Dimension</code> object contains
  1172.      * this component's height, and the <code>width</code>
  1173.      * field of the <code>Dimension</code> object contains
  1174.      * this component's width.
  1175.      * @return A <code>Dimension</code> object that indicates the
  1176.      * size of this component.
  1177.      * @see #setSize
  1178.      * @since JDK1.1
  1179.      */
  1180.     public Dimension getSize() {
  1181.     return size();
  1182.     }
  1183.  
  1184.     /**
  1185.      * @deprecated As of JDK version 1.1,
  1186.      * replaced by <code>getSize()</code>.
  1187.      */
  1188.     public Dimension size() {
  1189.     return new Dimension(width, height);
  1190.     }
  1191.  
  1192.     /**
  1193.      * Resizes this component so that it has width <code>width</code>
  1194.      * and <code>height</code>.
  1195.      * @param width The new width of this component in pixels.
  1196.      * @param height The new height of this component in pixels.
  1197.      * @see #getSize
  1198.      * @see #setBounds
  1199.      * @since JDK1.1
  1200.      */
  1201.     public void setSize(int width, int height) {
  1202.     resize(width, height);
  1203.     }
  1204.  
  1205.     /**
  1206.      * @deprecated As of JDK version 1.1,
  1207.      * replaced by <code>setSize(int, int)</code>.
  1208.      */
  1209.     public void resize(int width, int height) {
  1210.     setBounds(x, y, width, height);
  1211.     }
  1212.  
  1213.     /**
  1214.      * Resizes this component so that it has width <code>d.width</code>
  1215.      * and height <code>d.height</code>.
  1216.      * @param d The dimension specifying the new size 
  1217.      * of this component.
  1218.      * @see #setSize
  1219.      * @see #setBounds
  1220.      * @since JDK1.1
  1221.      */
  1222.     public void setSize(Dimension d) {
  1223.     resize(d);
  1224.     }
  1225.  
  1226.     /**
  1227.      * @deprecated As of JDK version 1.1,
  1228.      * replaced by <code>setSize(Dimension)</code>.
  1229.      */
  1230.     public void resize(Dimension d) {
  1231.     setSize(d.width, d.height);
  1232.     }
  1233.  
  1234.     /**
  1235.      * Gets the bounds of this component in the form of a
  1236.      * <code>Rectangle</code> object. The bounds specify this
  1237.      * component's width, height, and location relative to
  1238.      * its parent.
  1239.      * @return A rectangle indicating this component's bounds.
  1240.      * @see #setBounds
  1241.      * @see #getLocation
  1242.      * @see #getSize
  1243.      */
  1244.     public Rectangle getBounds() {
  1245.     return bounds();
  1246.     }
  1247.  
  1248.     /**
  1249.      * @deprecated As of JDK version 1.1,
  1250.      * replaced by <code>getBounds()</code>.
  1251.      */
  1252.     public Rectangle bounds() {
  1253.     return new Rectangle(x, y, width, height);
  1254.     }
  1255.  
  1256.     /**
  1257.      * Moves and resizes this component. The new location of the top-left
  1258.      * corner is specified by <code>x</code> and <code>y</code>, and the
  1259.      * new size is specified by <code>width</code> and <code>height</code>.
  1260.      * @param x The new <i>x</i>-coordinate of this component.
  1261.      * @param y The new <i>y</i>-coordinate of this component.
  1262.      * @param width The new <code>width</code> of this component.
  1263.      * @param height The new <code>height</code> of this 
  1264.      * component.
  1265.      * @see java.awt.Component#getBounds
  1266.      * @see java.awt.Component#setLocation(int, int)
  1267.      * @see java.awt.Component#setLocation(java.awt.Point)
  1268.      * @see java.awt.Component#setSize(int, int)
  1269.      * @see java.awt.Component#setSize(java.awt.Dimension)
  1270.      * @JDK1.1
  1271.      */
  1272.     public void setBounds(int x, int y, int width, int height) {
  1273.     reshape(x, y, width, height);
  1274.     }
  1275.  
  1276.     /**
  1277.      * @deprecated As of JDK version 1.1,
  1278.      * replaced by <code>setBounds(int, int, int, int)</code>.
  1279.      */
  1280.     public void reshape(int x, int y, int width, int height) {
  1281.     synchronized (getTreeLock()) {
  1282.         boolean resized = (this.width != width) || (this.height != height);
  1283.             boolean moved = (this.x != x) || (this.y != y);
  1284.         boolean isLightweight = peer instanceof java.awt.peer.LightweightPeer;
  1285.  
  1286.             if (resized) {
  1287.                 isPacked = false;
  1288.             }
  1289.         if (resized || moved) {
  1290.         if (isLightweight && visible) {
  1291.                     // Have the parent redraw the area this component occupied.
  1292.             repaint();
  1293.         }
  1294.         this.x = x;
  1295.         this.y = y;
  1296.         this.width = width;
  1297.         this.height = height;
  1298.         if (peer != null) {
  1299.             if (isLightweight) {
  1300.             peer.setBounds(x, y, width, height);
  1301.             } else {
  1302.             // native peer might be offset by more than direct
  1303.             // parent since parent might be lightweight.
  1304.             int nativeX = x;
  1305.             int nativeY = y;
  1306.             for(Component c = parent; (c != null) &&
  1307.                 (c.peer instanceof java.awt.peer.LightweightPeer);
  1308.                 c = c.parent) {
  1309.  
  1310.                 nativeX += c.x;
  1311.                 nativeY += c.y;
  1312.             }
  1313.             peer.setBounds(nativeX, nativeY, width, height);
  1314.             }
  1315.             if (resized) {
  1316.             invalidate();
  1317.  
  1318.                         if (componentListener != null ||
  1319.                            (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) {
  1320.                             ComponentEvent e = new ComponentEvent(this,
  1321.                                      ComponentEvent.COMPONENT_RESIZED);
  1322.                             Toolkit.getEventQueue().postEvent(e);
  1323.                         }
  1324.             }
  1325.                     if (moved &&
  1326.                         (componentListener != null ||
  1327.                          (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)) {
  1328.                             ComponentEvent e = new ComponentEvent(this,
  1329.                                      ComponentEvent.COMPONENT_MOVED);
  1330.                             Toolkit.getEventQueue().postEvent(e);
  1331.                     }
  1332.             if (parent != null && parent.valid) {
  1333.             parent.invalidate();
  1334.             }
  1335.         }
  1336.                 if (isLightweight && visible) {
  1337.                     // Have the parent redraw the area this component *now* occupies.
  1338.                     repaint();
  1339.                 }
  1340.         }
  1341.     }
  1342.     }
  1343.  
  1344.     /**
  1345.      * Moves and resizes this component to conform to the new
  1346.      * bounding rectangle <code>r</code>. This component's new
  1347.      * position is specified by <code>r.x</code> and <code>r.y</code>,
  1348.      * and its new size is specified by <code>r.width</code> and
  1349.      * <code>r.height</code>
  1350.      * @param r The new bounding rectangle for this component.
  1351.      * @see       java.awt.Component#getBounds
  1352.      * @see       java.awt.Component#setLocation(int, int)
  1353.      * @see       java.awt.Component#setLocation(java.awt.Point)
  1354.      * @see       java.awt.Component#setSize(int, int)
  1355.      * @see       java.awt.Component#setSize(java.awt.Dimension)
  1356.      * @since     JDK1.1
  1357.      */
  1358.     public void setBounds(Rectangle r) {
  1359.         setBounds(r.x, r.y, r.width, r.height);
  1360.     }
  1361.  
  1362.  
  1363.     /**
  1364.      * Return the current x coordinate of the components origin.
  1365.      * This method is preferable to writing component.getBounds().x,
  1366.      * or component.getLocation().x because it doesn't cause any
  1367.      * heap allocations.
  1368.      *
  1369.      * @return the current x coordinate of the components origin.
  1370.      * @since JDK1.2
  1371.      */
  1372.     public int getX() {
  1373.     return x;
  1374.     }
  1375.  
  1376.  
  1377.     /**
  1378.      * Return the current y coordinate of the components origin.
  1379.      * This method is preferable to writing component.getBounds().y,
  1380.      * or component.getLocation().y because it doesn't cause any
  1381.      * heap allocations.
  1382.      *
  1383.      * @return the current y coordinate of the components origin.
  1384.      * @since JDK1.2
  1385.      */
  1386.     public int getY() {
  1387.     return y;
  1388.     }
  1389.  
  1390.  
  1391.     /**
  1392.      * Return the current width of this component.
  1393.      * This method is preferable to writing component.getBounds().width,
  1394.      * or component.getSize().width because it doesn't cause any
  1395.      * heap allocations.
  1396.      *
  1397.      * @return the current width of this component.
  1398.      * @since JDK1.2
  1399.      */
  1400.     public int getWidth() {
  1401.     return width;
  1402.     }
  1403.  
  1404.  
  1405.     /**
  1406.      * Return the current height of this component.
  1407.      * This method is preferable to writing component.getBounds().height,
  1408.      * or component.getSize().height because it doesn't cause any
  1409.      * heap allocations.
  1410.      *
  1411.      * @return the current height of this component.
  1412.      * @since JDK1.2
  1413.      */
  1414.     public int getHeight() {
  1415.     return height;
  1416.     }
  1417.  
  1418.     /** 
  1419.      * Store the bounds of this component into "return value" <b>rv</b> and 
  1420.      * return <b>rv</b>.  If rv is null a new Rectangle is allocated.
  1421.      * This version of getBounds() is useful if the caller
  1422.      * wants to avoid allocating a new Rectangle object on the heap.
  1423.      * 
  1424.      * @param rv the return value, modified to the components bounds
  1425.      * @return rv
  1426.      */
  1427.     public Rectangle getBounds(Rectangle rv) {
  1428.         if (rv == null) {
  1429.             return new Rectangle(getX(), getY(), getWidth(), getHeight());
  1430.         }
  1431.         else {
  1432.             rv.setBounds(getX(), getY(), getWidth(), getHeight());
  1433.             return rv;
  1434.         }
  1435.     }
  1436.  
  1437.     /**
  1438.      * Store the width/height of this component into "return value" <b>rv</b> 
  1439.      * and return <b>rv</b>.   If rv is null a new Dimension object is
  1440.      * allocated.  This version of getSize() is useful if the 
  1441.      * caller wants to avoid allocating a new Dimension object on the heap.
  1442.      * 
  1443.      * @param rv the return value, modified to the components size
  1444.      * @return rv
  1445.      */
  1446.     public Dimension getSize(Dimension rv) {
  1447.         if (rv == null) {
  1448.             return new Dimension(getWidth(), getHeight());
  1449.         }
  1450.         else {
  1451.             rv.setSize(getWidth(), getHeight());
  1452.             return rv;
  1453.         }
  1454.     }
  1455.  
  1456.     /**
  1457.      * Store the x,y origin of this component into "return value" <b>rv</b> 
  1458.      * and return <b>rv</b>.   If rv is null a new Point is allocated.
  1459.      * This version of getLocation() is useful if the 
  1460.      * caller wants to avoid allocating a new Point object on the heap.
  1461.      * 
  1462.      * @param rv the return value, modified to the components location
  1463.      * @return rv
  1464.      */
  1465.     public Point getLocation(Point rv) {
  1466.         if (rv == null) {
  1467.             return new Point(getX(), getY());
  1468.         }
  1469.         else {
  1470.             rv.setLocation(getX(), getY());
  1471.             return rv;
  1472.         }
  1473.     }
  1474.  
  1475.     /**
  1476.      * Returns true if this component is completely opaque, returns
  1477.      * false by default.
  1478.      * <p>
  1479.      * An opaque component paints every pixel within its
  1480.      * rectangular region. A non-opaque component paints only some of
  1481.      * its pixels, allowing the pixels underneath it to "show through".
  1482.      * A component that does not fully paint its pixels therefore
  1483.      * provides a degree of transparency.  Only lightweight
  1484.      * components can be transparent.
  1485.      * <p>
  1486.      * Subclasses that guarantee to always completely paint their
  1487.      * contents should override this method and return true.  All
  1488.      * of the "heavyweight" AWT components are opaque.
  1489.      *
  1490.      * @return true if this component is completely opaque.
  1491.      * @see #isLightweight
  1492.      * @since JDK1.2
  1493.      */
  1494.     public boolean isOpaque() {
  1495.     return !isLightweight();
  1496.     }
  1497.  
  1498.  
  1499.     /**
  1500.      * A lightweight component doesn't have a native toolkit peer.
  1501.      * Subclasses of Component and Container, other than the ones
  1502.      * defined in this package like Button or Scrollbar, are lightweight.
  1503.      * All of the Swing components are lightweights.
  1504.      *
  1505.      * @return true if this component doesn't have a native peer
  1506.      * @since JDK1.2
  1507.      */
  1508.     public boolean isLightweight() {
  1509.         return getPeer() instanceof java.awt.peer.LightweightPeer;
  1510.     }
  1511.  
  1512.  
  1513.     /**
  1514.      * Gets the preferred size of this component.
  1515.      * @return A dimension object indicating this component's preferred size.
  1516.      * @see #getMinimumSize
  1517.      * @see java.awt.LayoutManager
  1518.      */
  1519.     public Dimension getPreferredSize() {
  1520.     return preferredSize();
  1521.     }
  1522.  
  1523.  
  1524.     /**
  1525.      * @deprecated As of JDK version 1.1,
  1526.      * replaced by <code>getPreferredSize()</code>.
  1527.      */
  1528.     public Dimension preferredSize() {
  1529.     /* Avoid grabbing the lock if a reasonable cached size value
  1530.          * is available.
  1531.      */
  1532.  
  1533.         Dimension dim = prefSize;
  1534.         if (dim != null && isValid()) {
  1535.         return dim;
  1536.     }
  1537.  
  1538.     synchronized (getTreeLock()) {
  1539.         prefSize = (peer != null) ?
  1540.                peer.preferredSize() :
  1541.                getMinimumSize();
  1542.         return prefSize;
  1543.     }
  1544.     }
  1545.  
  1546.     /**
  1547.      * Gets the mininimum size of this component.
  1548.      * @return A dimension object indicating this component's minimum size.
  1549.      * @see #getPreferredSize
  1550.      * @see java.awtLayoutManager
  1551.      */
  1552.     public Dimension getMinimumSize() {
  1553.           return minimumSize();
  1554.     }
  1555.  
  1556.     /**
  1557.      * @deprecated As of JDK version 1.1,
  1558.      * replaced by <code>getMinimumSize()</code>.
  1559.      */
  1560.     public Dimension minimumSize() {
  1561.     /* Avoid grabbing the lock if a reasonable cached size value
  1562.          * is available.
  1563.      */
  1564.         Dimension dim = minSize;
  1565.         if (dim != null && isValid()) {
  1566.         return dim;
  1567.     }
  1568.     synchronized (getTreeLock()) {
  1569.         minSize = (peer != null) ?
  1570.               peer.minimumSize() :
  1571.               size();
  1572.         return minSize;
  1573.     }
  1574.     }
  1575.  
  1576.     /**
  1577.      * Gets the maximum size of this component.
  1578.      * @return A dimension object indicating this component's maximum size.
  1579.      * @see #getMinimumSize
  1580.      * @see #getPreferredSize
  1581.      * @see LayoutManager
  1582.      */
  1583.     public Dimension getMaximumSize() {
  1584.     return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
  1585.     }
  1586.  
  1587.     /**
  1588.      * Returns the alignment along the x axis.  This specifies how
  1589.      * the component would like to be aligned relative to other
  1590.      * components.  The value should be a number between 0 and 1
  1591.      * where 0 represents alignment along the origin, 1 is aligned
  1592.      * the furthest away from the origin, 0.5 is centered, etc.
  1593.      */
  1594.     public float getAlignmentX() {
  1595.     return CENTER_ALIGNMENT;
  1596.     }
  1597.  
  1598.     /**
  1599.      * Returns the alignment along the y axis.  This specifies how
  1600.      * the component would like to be aligned relative to other
  1601.      * components.  The value should be a number between 0 and 1
  1602.      * where 0 represents alignment along the origin, 1 is aligned
  1603.      * the furthest away from the origin, 0.5 is centered, etc.
  1604.      */
  1605.     public float getAlignmentY() {
  1606.     return CENTER_ALIGNMENT;
  1607.     }
  1608.  
  1609.     /**
  1610.      * Prompts the layout manager to lay out this component. This is
  1611.      * usually called when the component (more specifically, container)
  1612.      * is validated.
  1613.      * @see #validate
  1614.      * @see LayoutManager
  1615.      */
  1616.     public void doLayout() {
  1617.         layout();
  1618.     }
  1619.  
  1620.     /**
  1621.      * @deprecated As of JDK version 1.1,
  1622.      * replaced by <code>doLayout()</code>.
  1623.      */
  1624.     public void layout() {
  1625.     }
  1626.  
  1627.     /**
  1628.      * Ensures that this component has a valid layout.  This method is
  1629.      * primarily intended to operate on instances of <code>Container</code>.
  1630.      * @see       java.awt.Component#invalidate
  1631.      * @see       java.awt.Component#doLayout()
  1632.      * @see       java.awt.LayoutManager
  1633.      * @see       java.awt.Container#validate
  1634.      * @since     JDK1.0
  1635.      */
  1636.     public void validate() {
  1637.         if (!valid) {
  1638.         synchronized (getTreeLock()) {
  1639.             ComponentPeer peer = this.peer;
  1640.             if (!valid && peer != null) {
  1641.             Font newfont = getFont();
  1642.             Font oldfont = peerFont;
  1643.             if (newfont != oldfont && (oldfont == null
  1644.                                                 || !oldfont.equals(newfont))) {
  1645.                 peer.setFont(newfont);
  1646.             peerFont = newfont;
  1647.             }
  1648.         }
  1649.         }
  1650.         valid = true;
  1651.     }
  1652.     }
  1653.  
  1654.     /**
  1655.      * Invalidates this component.  This component and all parents
  1656.      * above it are marked as needing to be laid out.  This method can
  1657.      * be called often, so it needs to execute quickly.
  1658.      * @see       java.awt.Component#validate
  1659.      * @see       java.awt.Component#doLayout
  1660.      * @see       java.awt.LayoutManager
  1661.      * @since     JDK1.0
  1662.      */
  1663.     public void invalidate() {
  1664.     synchronized (getTreeLock()) {
  1665.         /* Nullify cached layout and size information.
  1666.          * For efficiency, propagate invalidate() upwards only if
  1667.          * some other component hasn't already done so first.
  1668.              */
  1669.         valid = false;
  1670.             prefSize = null;
  1671.             minSize = null;
  1672.         if (parent != null && parent.valid) {
  1673.         parent.invalidate();
  1674.         }
  1675.     }
  1676.     }
  1677.  
  1678.     /**
  1679.      * Creates a graphics context for this component. This method will
  1680.      * return <code>null</code> if this component is currently not on
  1681.      * the screen.
  1682.      * @return A graphics context for this component, or <code>null</code>
  1683.      *             if it has none.
  1684.      * @see       java.awt.Component#paint
  1685.      * @since     JDK1.0
  1686.      */
  1687.     public Graphics getGraphics() {
  1688.     if (peer instanceof java.awt.peer.LightweightPeer) {
  1689.         // This is for a lightweight component, need to
  1690.         // translate coordinate spaces and clip relative
  1691.         // to the parent.
  1692.         Graphics g = parent.getGraphics();
  1693.         if (g instanceof ConstrainableGraphics) {
  1694.         ((ConstrainableGraphics) g).constrain(x, y, width, height);
  1695.         } else {
  1696.         g.translate(x,y);
  1697.         g.setClip(0, 0, width, height);
  1698.         }
  1699.         g.setFont(getFont());
  1700.         return g;
  1701.     } else {
  1702.         ComponentPeer peer = this.peer;
  1703.         return (peer != null) ? peer.getGraphics() : null;
  1704.     }
  1705.     }
  1706.  
  1707.     /**
  1708.      * Gets the font metrics for the specified font.
  1709.      * @param font The font for which font metrics is to be 
  1710.      * obtained.
  1711.      * @return The font metrics for <code>font</code>.
  1712.      * @param     font   the font.
  1713.      * @return    the font metrics for the specified font.
  1714.      * @see       java.awt.Component#getFont
  1715.      * @see       java.awt.Component#getPeer()
  1716.      * @see       java.awt.peer.ComponentPeer#getFontMetrics(java.awt.Font)
  1717.      * @see       java.awt.Toolkit#getFontMetrics(java.awt.Font)
  1718.      * @since     JDK1.0
  1719.      */
  1720.     public FontMetrics getFontMetrics(Font font) {
  1721.         if (sun.java2d.loops.RasterOutputManager.usesPlatformFont()) {
  1722.             if (peer != null &&
  1723.                 !(peer instanceof java.awt.peer.LightweightPeer)) {
  1724.                 return peer.getFontMetrics(font);
  1725.             }
  1726.         }
  1727.         if (parent != null) {
  1728.             Graphics g = parent.getGraphics();
  1729.             if (g != null) {
  1730.                 return g.getFontMetrics(font);
  1731.             }
  1732.         }
  1733.  
  1734.         return getToolkit().getFontMetrics(font);
  1735.     }
  1736.  
  1737.     /**
  1738.      * Sets the cursor image to the specified cursor.  This cursor
  1739.      * image is displayed when the <code>contains</code> method for
  1740.      * this component returns true for the current cursor location.
  1741.      * Setting the cursor of a <code>Container</code> causes that cursor 
  1742.      * to be displayed within all of the container's subcomponents,
  1743.      * except for any subcomponents that are using a non-default cursor. 
  1744.      * 
  1745.      * @param cursor One of the constants defined 
  1746.      *        by the <code>Cursor</code> class.
  1747.      *        If this parameter is null then this component will inherit
  1748.      *        the cursor of its parent.
  1749.      * @see       java.awt.Component#getCursor
  1750.      * @see       java.awt.Component#contains
  1751.      * @see       java.awt.Toolkit#createCustomCursor
  1752.      * @see       java.awt.Cursor
  1753.      * @since     JDK1.1
  1754.      */
  1755.     public synchronized void setCursor(Cursor cursor) {
  1756.     this.cursor = cursor;
  1757.         ComponentPeer peer = this.peer;
  1758.     if (peer != null) {
  1759.         peer.setCursor(cursor);
  1760.     }
  1761.     }
  1762.  
  1763.     /**
  1764.      * Gets the cursor set on this component.
  1765.      * @return     The cursor for this component.
  1766.      * @see        java.awt.Component#setCursor
  1767.      * @see        java.awt.Cursor
  1768.      * @since      JDK1.1
  1769.      */
  1770.     public Cursor getCursor() {
  1771.     return cursor;
  1772.     }
  1773.  
  1774.     /**
  1775.      * Paints this component.  This method is called when the contents
  1776.      * of the component should be painted in response to the component
  1777.      * first being shown or damage needing repair.  The clip rectangle
  1778.      * in the Graphics parameter will be set to the area which needs
  1779.      * to be painted.
  1780.      * @param g The graphics context to use for painting.
  1781.      * @see       java.awt.Component#update
  1782.      * @since     JDK1.0
  1783.      */
  1784.     public void paint(Graphics g) {
  1785.     }
  1786.  
  1787.     /**
  1788.      * Updates this component.
  1789.      * <p>
  1790.      * The AWT calls the <code>update</code> method in response to a
  1791.      * call to <code>repaint</code. The appearance of the
  1792.      * component on the screen has not changed since the last call to
  1793.      * <code>update</code> or <code>paint</code>. You can assume that
  1794.      * the background is not cleared.
  1795.      * <p>
  1796.      * The <code>update</code>method of <code>Component</code>
  1797.      * does the following:
  1798.      * <p>
  1799.      * <blockquote><ul>
  1800.      * <li>Clears this component by filling it
  1801.      *      with the background color.
  1802.      * <li>Sets the color of the graphics context to be
  1803.      *     the foreground color of this component.
  1804.      * <li>Calls this component's <code>paint</code>
  1805.      *     method to completely redraw this component.
  1806.      * </ul></blockquote>
  1807.      * <p>
  1808.      * The origin of the graphics context, its
  1809.      * (<code>0</code>, <code>0</code>) coordinate point, is the
  1810.      * top-left corner of this component. The clipping region of the
  1811.      * graphics context is the bounding rectangle of this component.
  1812.      * @param g the specified context to use for updating.
  1813.      * @see       java.awt.Component#paint
  1814.      * @see       java.awt.Component#repaint()
  1815.      * @since     JDK1.0
  1816.      */
  1817.     public void update(Graphics g) {
  1818.     if ((! (peer instanceof java.awt.peer.LightweightPeer)) &&
  1819.             (! (this instanceof Label)) && (! (this instanceof TextField))){
  1820.         g.clearRect(0, 0, width, height);
  1821.     }
  1822.     paint(g);
  1823.     }
  1824.  
  1825.     /**
  1826.      * Paints this component and all of its subcomponents.
  1827.      * <p>
  1828.      * The origin of the graphics context, its
  1829.      * (<code>0</code>, <code>0</code>) coordinate point, is the
  1830.      * top-left corner of this component. The clipping region of the
  1831.      * graphics context is the bounding rectangle of this component.
  1832.      * @param     g   the graphics context to use for painting.
  1833.      * @see       java.awt.Component#paint
  1834.      * @since     JDK1.0
  1835.      */
  1836.     public void paintAll(Graphics g) {
  1837.     ComponentPeer peer = this.peer;
  1838.     if (visible && (peer != null)) {
  1839.         validate();
  1840.         if (peer instanceof java.awt.peer.LightweightPeer) {
  1841.         paint(g);
  1842.         } else {
  1843.         peer.paint(g);
  1844.         }
  1845.     }
  1846.     }
  1847.  
  1848.     /**
  1849.      * Repaints this component.
  1850.      * <p>
  1851.      * This method causes a call to this component's <code>update</code>
  1852.      * method as soon as possible.
  1853.      * @see       java.awt.Component#update(java.awt.Graphics)
  1854.      * @since     JDK1.0
  1855.      */
  1856.     public void repaint() {
  1857.         /*
  1858.     getToolkit().getEventQueue().removeSourceEvents(this, PaintEvent.PAINT);
  1859.     */
  1860.     repaint(0, 0, 0, width, height);
  1861.     }
  1862.  
  1863.     /**
  1864.      * Repaints the component. This will result in a
  1865.      * call to <code>update</code> within <em>tm</em> milliseconds.
  1866.      * @param tm maximum time in milliseconds before update
  1867.      * @see #paint
  1868.      * @see java.awt.Component#update(java.awt.Graphics)
  1869.      * @since JDK1.0
  1870.      */
  1871.     public void repaint(long tm) {
  1872.     repaint(tm, 0, 0, width, height);
  1873.     }
  1874.  
  1875.     /**
  1876.      * Repaints the specified rectangle of this component.
  1877.      * <p>
  1878.      * This method causes a call to this component's <code>update</code>
  1879.      * method as soon as possible.
  1880.      * @param     x   the <i>x</i> coordinate.
  1881.      * @param     y   the <i>y</i> coordinate.
  1882.      * @param     width   the width.
  1883.      * @param     height  the height.
  1884.      * @see       java.awt.Component#update(java.awt.Graphics)
  1885.      * @since     JDK1.0
  1886.      */
  1887.     public void repaint(int x, int y, int width, int height) {
  1888.     repaint(0, x, y, width, height);
  1889.     }
  1890.  
  1891.     /**
  1892.      * Repaints the specified rectangle of this component within
  1893.      * <code>tm</code> milliseconds.
  1894.      * <p>
  1895.      * This method causes a call to this component's
  1896.      * <code>update</code> method.
  1897.      * @param     tm   maximum time in milliseconds before update.
  1898.      * @param     x    the <i>x</i> coordinate.
  1899.      * @param     y    the <i>y</i> coordinate.
  1900.      * @param     width    the width.
  1901.      * @param     height   the height.
  1902.      * @see       java.awt.Component#update(java.awt.Graphics)
  1903.      * @since     JDK1.0
  1904.      */
  1905.     public void repaint(long tm, int x, int y, int width, int height) {
  1906.     if (this.peer instanceof java.awt.peer.LightweightPeer) {
  1907.         // Needs to be translated to parent coordinates since
  1908.         // a parent native container provides the actual repaint
  1909.         // services.  Additionally, the request is restricted to
  1910.         // the bounds of the component.
  1911.         int px = this.x + ((x < 0) ? 0 : x);
  1912.         int py = this.y + ((y < 0) ? 0 : y);
  1913.         int pwidth = (width > this.width) ? this.width : width;
  1914.         int pheight = (height > this.height) ? this.height : height;
  1915.         parent.repaint(tm, px, py, pwidth, pheight);
  1916.     } else {
  1917.         ComponentPeer peer = this.peer;
  1918.         if ((peer != null) && (width > 0) && (height > 0)) {
  1919.         peer.repaint(tm, x, y, width, height);
  1920.         }
  1921.     }
  1922.     }
  1923.  
  1924.     /**
  1925.      * Prints this component. Applications should override this method
  1926.      * for components that must do special processing before being
  1927.      * printed or should be printed differently than they are painted.
  1928.      * <p>
  1929.      * The default implementation of this method calls the
  1930.      * <code>paint</code> method.
  1931.      * <p>
  1932.      * The origin of the graphics context, its
  1933.      * (<code>0</code>, <code>0</code>) coordinate point, is the
  1934.      * top-left corner of this component. The clipping region of the
  1935.      * graphics context is the bounding rectangle of this component.
  1936.      * @param     g   the graphics context to use for printing.
  1937.      * @see       java.awt.Component#paint(java.awt.Graphics)
  1938.      * @since     JDK1.0
  1939.      */
  1940.     public void print(Graphics g) {
  1941.     paint(g);
  1942.     }
  1943.  
  1944.     /**
  1945.      * Prints this component and all of its subcomponents.
  1946.      * <p>
  1947.      * The origin of the graphics context, its
  1948.      * (<code>0</code>, <code>0</code>) coordinate point, is the
  1949.      * top-left corner of this component. The clipping region of the
  1950.      * graphics context is the bounding rectangle of this component.
  1951.      * @param     g   the graphics context to use for printing.
  1952.      * @see       java.awt.Component#print(java.awt.Graphics)
  1953.      * @since     JDK1.0
  1954.      */
  1955.     public void printAll(Graphics g) {
  1956.     ComponentPeer peer = this.peer;
  1957.     if (visible && (peer != null)) {
  1958.         validate();
  1959.         Graphics cg = g.create(0, 0, width, height);
  1960.         cg.setFont(getFont());
  1961.         try {
  1962.             if (peer instanceof java.awt.peer.LightweightPeer) {
  1963.             lightweightPrint(g);
  1964.         }
  1965.         else {
  1966.             peer.print(g);
  1967.         }
  1968.         } finally {
  1969.             cg.dispose();
  1970.         }
  1971.     }
  1972.     }
  1973.  
  1974.     /**
  1975.      * Simulates the peer callbacks into java.awt for printing of
  1976.      * lightweight Components.
  1977.      * @param     g   the graphics context to use for printing.
  1978.      * @see       #printAll
  1979.      */
  1980.     void lightweightPrint(Graphics g) {
  1981.         print(g);
  1982.     }
  1983.  
  1984.     /**
  1985.      * Repaints the component when the image has changed.
  1986.      * This <code>imageUpdate</code> method of an <code>ImageObserver</code>
  1987.      * is called when more information about an
  1988.      * image which had been previously requested using an asynchronous
  1989.      * routine such as the <code>drawImage</code> method of
  1990.      * <code>Graphics</code> becomes available.
  1991.      * See the definition of <code>imageUpdate</code> for
  1992.      * more information on this method and its arguments.
  1993.      * <p>
  1994.      * The <code>imageUpdate</code> method of <code>Component</code>
  1995.      * incrementally draws an image on the component as more of the bits
  1996.      * of the image are available.
  1997.      * <p>
  1998.      * If the system property <code>awt.image.incrementalDraw</code>
  1999.      * is missing or has the value <code>true</code>, the image is
  2000.      * incrementally drawn, If the system property has any other value,
  2001.      * then the image is not drawn until it has been completely loaded.
  2002.      * <p>
  2003.      * Also, if incremental drawing is in effect, the value of the
  2004.      * system property <code>awt.image.redrawrate</code> is interpreted
  2005.      * as an integer to give the maximum redraw rate, in milliseconds. If
  2006.      * the system property is missing or cannot be interpreted as an
  2007.      * integer, the redraw rate is once every 100ms.
  2008.      * <p>
  2009.      * The interpretation of the <code>x</code>, <code>y</code>,
  2010.      * <code>width</code>, and <code>height</code> arguments depends on
  2011.      * the value of the <code>infoflags</code> argument.
  2012.      * @param     img   the image being observed.
  2013.      * @param     infoflags   see <code>imageUpdate</code> for more information.
  2014.      * @param     x   the <i>x</i> coordinate.
  2015.      * @param     y   the <i>y</i> coordinate.
  2016.      * @param     width    the width.
  2017.      * @param     height   the height.
  2018.      * @return    <code>true</code> if the flags indicate that the
  2019.      *            image is completely loaded;
  2020.      *            <code>false</code> otherwise.
  2021.      * @see     java.awt.image.ImageObserver
  2022.      * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, java.awt.Color, java.awt.image.ImageObserver)
  2023.      * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  2024.      * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, java.awt.Color, java.awt.image.ImageObserver)
  2025.      * @see     java.awt.Graphics#drawImage(java.awt.Image, int, int, int, int, java.awt.image.ImageObserver)
  2026.      * @see     java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
  2027.      * @since   JDK1.0
  2028.      */
  2029.     public boolean imageUpdate(Image img, int flags,
  2030.                    int x, int y, int w, int h) {
  2031.     int rate = -1;
  2032.     if ((flags & (FRAMEBITS|ALLBITS)) != 0) {
  2033.         rate = 0;
  2034.     } else if ((flags & SOMEBITS) != 0) {
  2035.         if (isInc) {
  2036.         try {
  2037.             rate = incRate;
  2038.             if (rate < 0)
  2039.             rate = 0;
  2040.         } catch (Exception e) {
  2041.             rate = 100;
  2042.         }
  2043.         }
  2044.     }
  2045.     if (rate >= 0) {
  2046.         repaint(rate, 0, 0, width, height);
  2047.     }
  2048.     return (flags & (ALLBITS|ABORT)) == 0;
  2049.     }
  2050.  
  2051.     /**
  2052.      * Creates an image from the specified image producer.
  2053.      * @param     producer  the image producer
  2054.      * @return    the image produced.
  2055.      * @since     JDK1.0
  2056.      */
  2057.     public Image createImage(ImageProducer producer) {
  2058.         ComponentPeer peer = this.peer;
  2059.     if ((peer != null) && ! (peer instanceof java.awt.peer.LightweightPeer)) {
  2060.         return peer.createImage(producer);
  2061.     }
  2062.     return getToolkit().createImage(producer);
  2063.     }
  2064.  
  2065.     /**
  2066.      * Creates an off-screen drawable image
  2067.      *     to be used for double buffering.
  2068.      * @param     width the specified width.
  2069.      * @param     height the specified height.
  2070.      * @return    an off-screen drawable image,
  2071.      *            which can be used for double buffering.
  2072.      * @since     JDK1.0
  2073.      */
  2074.     public Image createImage(int width, int height) {
  2075.         ComponentPeer peer = this.peer;
  2076.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2077.         return parent.createImage(width, height);
  2078.     } else {
  2079.         return (peer != null) ? peer.createImage(width, height) : null;
  2080.     }
  2081.     }
  2082.  
  2083.     /**
  2084.      * Prepares an image for rendering on this component.  The image
  2085.      * data is downloaded asynchronously in another thread and the
  2086.      * appropriate screen representation of the image is generated.
  2087.      * @param     image   the <code>Image</code> for which to
  2088.      *                    prepare a screen representation.
  2089.      * @param     observer   the <code>ImageObserver</code> object
  2090.      *                       to be notified as the image is being prepared.
  2091.      * @return    <code>true</code> if the image has already been fully prepared;
  2092.                   <code>false</code> otherwise.
  2093.      * @since     JDK1.0
  2094.      */
  2095.     public boolean prepareImage(Image image, ImageObserver observer) {
  2096.         return prepareImage(image, -1, -1, observer);
  2097.     }
  2098.  
  2099.     /**
  2100.      * Prepares an image for rendering on this component at the
  2101.      * specified width and height.
  2102.      * <p>
  2103.      * The image data is downloaded asynchronously in another thread,
  2104.      * and an appropriately scaled screen representation of the image is
  2105.      * generated.
  2106.      * @param     image    the instance of <code>Image</code>
  2107.      *            for which to prepare a screen representation.
  2108.      * @param     width    the width of the desired screen representation.
  2109.      * @param     height   the height of the desired screen representation.
  2110.      * @param     observer   the <code>ImageObserver</code> object
  2111.      *            to be notified as the image is being prepared.
  2112.      * @return    <code>true</code> if the image has already been fully prepared;
  2113.                   <code>false</code> otherwise.
  2114.      * @see       java.awt.image.ImageObserver
  2115.      * @since     JDK1.0
  2116.      */
  2117.     public boolean prepareImage(Image image, int width, int height,
  2118.                 ImageObserver observer) {
  2119.         ComponentPeer peer = this.peer;
  2120.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2121.         return parent.prepareImage(image, width, height, observer);
  2122.     } else {
  2123.         return (peer != null)
  2124.         ? peer.prepareImage(image, width, height, observer)
  2125.         : getToolkit().prepareImage(image, width, height, observer);
  2126.     }
  2127.     }
  2128.  
  2129.     /**
  2130.      * Returns the status of the construction of a screen representation
  2131.      * of the specified image.
  2132.      * <p>
  2133.      * This method does not cause the image to begin loading. An
  2134.      * application must use the <code>prepareImage</code> method
  2135.      * to force the loading of an image.
  2136.      * <p>
  2137.      * Information on the flags returned by this method can be found
  2138.      * with the discussion of the <code>ImageObserver</code> interface.
  2139.      * @param     image   the <code>Image</code> object whose status
  2140.      *            is being checked.
  2141.      * @param     observer   the <code>ImageObserver</code>
  2142.      *            object to be notified as the image is being prepared.
  2143.      * @return  the bitwise inclusive <b>OR</b> of
  2144.      *            <code>ImageObserver</code> flags indicating what
  2145.      *            information about the image is currently available.
  2146.      * @see      java.awt.Component#prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  2147.      * @see      java.awt.Toolkit#checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  2148.      * @see      java.awt.image.ImageObserver
  2149.      * @since    JDK1.0
  2150.      */
  2151.     public int checkImage(Image image, ImageObserver observer) {
  2152.         return checkImage(image, -1, -1, observer);
  2153.     }
  2154.  
  2155.     /**
  2156.      * Returns the status of the construction of a screen representation
  2157.      * of the specified image.
  2158.      * <p>
  2159.      * This method does not cause the image to begin loading. An
  2160.      * application must use the <code>prepareImage</code> method
  2161.      * to force the loading of an image.
  2162.      * <p>
  2163.      * The <code>checkImage</code> method of <code>Component</code>
  2164.      * calls its peer's <code>checkImage</code> method to calculate
  2165.      * the flags. If this component does not yet have a peer, the
  2166.      * component's toolkit's <code>checkImage</code> method is called
  2167.      * instead.
  2168.      * <p>
  2169.      * Information on the flags returned by this method can be found
  2170.      * with the discussion of the <code>ImageObserver</code> interface.
  2171.      * @param     image   the <code>Image</code> object whose status
  2172.      *                    is being checked.
  2173.      * @param     width   the width of the scaled version
  2174.      *                    whose status is to be checked.
  2175.      * @param     height  the height of the scaled version
  2176.      *                    whose status is to be checked.
  2177.      * @param     observer   the <code>ImageObserver</code> object
  2178.      *                    to be notified as the image is being prepared.
  2179.      * @return    the bitwise inclusive <b>OR</b> of
  2180.      *            <code>ImageObserver</code> flags indicating what
  2181.      *            information about the image is currently available.
  2182.      * @see      java.awt.Component#prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  2183.      * @see      java.awt.Toolkit#checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver)
  2184.      * @see      java.awt.image.ImageObserver#_top_
  2185.      * @since    JDK1.0
  2186.      */
  2187.     public int checkImage(Image image, int width, int height,
  2188.               ImageObserver observer) {
  2189.         ComponentPeer peer = this.peer;
  2190.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2191.         return parent.checkImage(image, width, height, observer);
  2192.     } else {
  2193.         return (peer != null)
  2194.         ? peer.checkImage(image, width, height, observer)
  2195.         : getToolkit().checkImage(image, width, height, observer);
  2196.     }
  2197.     }
  2198.  
  2199.     /**
  2200.      * Checks whether this component "contains" the specified point,
  2201.      * where <code>x</code> and <code>y</code> are defined to be
  2202.      * relative to the coordinate system of this component.
  2203.      * @param     x   the <i>x</i> coordinate of the point.
  2204.      * @param     y   the <i>y</i> coordinate of the point.
  2205.      * @see       java.awt.Component#getComponentAt(int, int)
  2206.      * @since     JDK1.1
  2207.      */
  2208.     public boolean contains(int x, int y) {
  2209.         return inside(x, y);
  2210.     }
  2211.  
  2212.     /**
  2213.      * @deprecated As of JDK version 1.1,
  2214.      * replaced by contains(int, int).
  2215.      */
  2216.     public boolean inside(int x, int y) {
  2217.     return (x >= 0) && (x < width) && (y >= 0) && (y < height);
  2218.     }
  2219.  
  2220.     /**
  2221.      * Checks whether this component "contains" the specified point,
  2222.      * where the point's <i>x</i> and <i>y</i> coordinates are defined
  2223.      * to be relative to the coordinate system of this component.
  2224.      * @param     p     the point.
  2225.      * @see       java.awt.Component#getComponentAt(java.awt.Point)
  2226.      * @since     JDK1.1
  2227.      */
  2228.     public boolean contains(Point p) {
  2229.     return contains(p.x, p.y);
  2230.     }
  2231.  
  2232.     /**
  2233.      * Determines if this component or one of its immediate
  2234.      * subcomponents contains the (<i>x</i>, <i>y</i>) location,
  2235.      * and if so, returns the containing component. This method only
  2236.      * looks one level deep. If the point (<i>x</i>, <i>y</i>) is
  2237.      * inside a subcomponent that itself has subcomponents, it does not
  2238.      * go looking down the subcomponent tree.
  2239.      * <p>
  2240.      * The <code>locate</code> method of <code>Component</code> simply
  2241.      * returns the component itself if the (<i>x</i>, <i>y</i>)
  2242.      * coordinate location is inside its bounding box, and <code>null</code>
  2243.      * otherwise.
  2244.      * @param     x   the <i>x</i> coordinate.
  2245.      * @param     y   the <i>y</i> coordinate.
  2246.      * @return    the component or subcomponent that contains the
  2247.      *                (<i>x</i>, <i>y</i>) location;
  2248.      *                <code>null</code> if the location
  2249.      *                is outside this component.
  2250.      * @see       java.awt.Component#contains(int, int)
  2251.      * @since     JDK1.0
  2252.      */
  2253.     public Component getComponentAt(int x, int y) {
  2254.     return locate(x, y);
  2255.     }
  2256.  
  2257.     /**
  2258.      * @deprecated As of JDK version 1.1,
  2259.      * replaced by getComponentAt(int, int).
  2260.      */
  2261.     public Component locate(int x, int y) {
  2262.     return contains(x, y) ? this : null;
  2263.     }
  2264.  
  2265.     /**
  2266.      * Returns the component or subcomponent that contains the
  2267.      * specified point.
  2268.      * @param     p   the point.
  2269.      * @see       java.awt.Component#contains
  2270.      * @since     JDK1.1
  2271.      */
  2272.     public Component getComponentAt(Point p) {
  2273.     return getComponentAt(p.x, p.y);
  2274.     }
  2275.  
  2276.     /**
  2277.      * @deprecated As of JDK version 1.1,
  2278.      * replaced by <code>dispatchEvent(AWTEvent e)</code>.
  2279.      */
  2280.     public void deliverEvent(Event e) {
  2281.     postEvent(e);
  2282.     }
  2283.  
  2284.     /**
  2285.      * Dispatches an event to this component or one of its sub components.
  2286.      * @param e the event
  2287.      */
  2288.     public final void dispatchEvent(AWTEvent e) {
  2289.         dispatchEventImpl(e);
  2290.     }
  2291.  
  2292.     void dispatchEventImpl(AWTEvent e) {
  2293.         int id = e.getID();
  2294.  
  2295.     /*
  2296.      * 0. Allow the Toolkit to pass this to AWTEventListeners.
  2297.      */
  2298.     Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
  2299.  
  2300.         /*
  2301.      * 1. Allow input methods to process the event
  2302.      */
  2303.     if (areInputMethodsEnabled()
  2304.             && (
  2305.             // For passive clients of the input method framework
  2306.                 // we need to pass on InputMethodEvents since some host
  2307.                 // input method adapters send them through the Java
  2308.                 // event queue instead of directly to the component,
  2309.                 // and the input context also handles the Java root window
  2310.                 ((e instanceof InputMethodEvent) && (getInputMethodRequests() == null))
  2311.                 ||
  2312.                 // Otherwise, we only pass on low-level events, because
  2313.                 // a) input methods shouldn't know about semantic events
  2314.                 // b) passing on the events takes time
  2315.                 // c) isConsumed() is always true for semantic events.
  2316.                 // We exclude paint events since they may be numerous and shouldn't matter.
  2317.                 (e instanceof ComponentEvent) && !(e instanceof PaintEvent))) {
  2318.             InputContext inputContext = getInputContext();
  2319.             if (inputContext != null) {
  2320.                 inputContext.dispatchEvent(e);
  2321.             if (e.isConsumed()) {
  2322.                 return;
  2323.             }
  2324.         }
  2325.         }
  2326.  
  2327.         /*
  2328.          * 2. Pre-process any special events before delivery
  2329.          */
  2330.         switch(id) {
  2331.           // Handling of the PAINT and UPDATE events is now done in the
  2332.           // peer's handleEvent() method so the background can be cleared
  2333.           // selectively for non-native components on Windows only.
  2334.           // - Fred.Ecks@Eng.sun.com, 5-8-98
  2335.  
  2336.           case FocusEvent.FOCUS_GAINED:
  2337.             if (parent != null && !(this instanceof Window)) {
  2338.                 parent.setFocusOwner(this);
  2339.             }
  2340.             break;
  2341.  
  2342.           case FocusEvent.FOCUS_LOST:
  2343.       break;
  2344.  
  2345.           case KeyEvent.KEY_PRESSED:
  2346.           case KeyEvent.KEY_RELEASED:
  2347.             Container p = (Container)((this instanceof Container) ? this : parent);
  2348.             if (p != null) {
  2349.                 p.preProcessKeyEvent((KeyEvent)e);
  2350.                 if (e.isConsumed()) {
  2351.                     return;
  2352.                 }
  2353.             }
  2354.             break;
  2355.  
  2356. /*
  2357.           case MouseEvent.MOUSE_PRESSED:
  2358.             if (isFocusTraversable()) {
  2359.                 requestFocus();
  2360.             }
  2361.             break;
  2362.             */
  2363.           default:
  2364.             break;
  2365.         }
  2366.  
  2367.         /*
  2368.          * 3. Deliver event for normal processing
  2369.          */
  2370.         if (newEventsOnly) {
  2371.             // Filtering needs to really be moved to happen at a lower
  2372.             // level in order to get maximum performance gain;  it is
  2373.             // here temporarily to ensure the API spec is honored.
  2374.             //
  2375.             if (eventEnabled(e)) {
  2376.                 processEvent(e);
  2377.             }
  2378.  
  2379.         } else if (!(e instanceof MouseEvent && !postsOldMouseEvents())) {
  2380.             //
  2381.             // backward compatibility
  2382.             //
  2383.             Event olde = e.convertToOld();
  2384.             if (olde != null) {
  2385.                 int key = olde.key;
  2386.                 int modifiers = olde.modifiers;
  2387.  
  2388.                 postEvent(olde);
  2389.                 if (olde.isConsumed()) {
  2390.                     e.consume();
  2391.                 }
  2392.                 // if target changed key or modifier values, copy them
  2393.                 // back to original event
  2394.                 //
  2395.                 switch(olde.id) {
  2396.                   case Event.KEY_PRESS:
  2397.                   case Event.KEY_RELEASE:
  2398.                   case Event.KEY_ACTION:
  2399.                   case Event.KEY_ACTION_RELEASE:
  2400.                     if (olde.key != key) {
  2401.                        ((KeyEvent)e).setKeyChar(olde.getKeyEventChar());
  2402.                     }
  2403.                     if (olde.modifiers != modifiers) {
  2404.                        ((KeyEvent)e).setModifiers(olde.modifiers);
  2405.                     }
  2406.                     break;
  2407.                   default:
  2408.                     break;
  2409.                 }
  2410.             }
  2411.         }
  2412.  
  2413.         /*
  2414.          * 4. If no one has consumed a key event, propagate it
  2415.          * up the containment hierarchy to ensure that menu shortcuts
  2416.          * and keyboard traversal will work properly.
  2417.          */
  2418.         if (!e.isConsumed() && e instanceof java.awt.event.KeyEvent) {
  2419.             Container p = (Container)((this instanceof Container) ? this : parent);
  2420.             if (p != null) {
  2421.                 p.postProcessKeyEvent((KeyEvent)e);
  2422.             }
  2423.         }
  2424.  
  2425.         /*
  2426.          * 5. Allow the peer to process the event
  2427.          */
  2428.         if (peer != null) {
  2429.             peer.handleEvent(e);
  2430.         }
  2431.     } // dispatchEventImpl()
  2432.  
  2433.     boolean areInputMethodsEnabled() {
  2434.         // in 1.2, we assume input method support is required for all
  2435.         // components that handle key events, but components can turn off
  2436.         // input methods by calling enableInputMethods(false).
  2437.         return ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) &&
  2438.             ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null);
  2439.     }
  2440.  
  2441.     // REMIND: remove when filtering is handled at lower level
  2442.     boolean eventEnabled(AWTEvent e) {
  2443.         switch(e.id) {
  2444.           case ComponentEvent.COMPONENT_MOVED:
  2445.           case ComponentEvent.COMPONENT_RESIZED:
  2446.           case ComponentEvent.COMPONENT_SHOWN:
  2447.           case ComponentEvent.COMPONENT_HIDDEN:
  2448.             if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
  2449.                 componentListener != null) {
  2450.                 return true;
  2451.             }
  2452.             break;
  2453.           case FocusEvent.FOCUS_GAINED:
  2454.           case FocusEvent.FOCUS_LOST:
  2455.             if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 ||
  2456.                 focusListener != null) {
  2457.                 return true;
  2458.             }
  2459.             break;
  2460.           case KeyEvent.KEY_PRESSED:
  2461.           case KeyEvent.KEY_RELEASED:
  2462.           case KeyEvent.KEY_TYPED:
  2463.             if ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 ||
  2464.                 keyListener != null) {
  2465.                 return true;
  2466.             }
  2467.             break;
  2468.           case MouseEvent.MOUSE_PRESSED:
  2469.           case MouseEvent.MOUSE_RELEASED:
  2470.           case MouseEvent.MOUSE_ENTERED:
  2471.           case MouseEvent.MOUSE_EXITED:
  2472.           case MouseEvent.MOUSE_CLICKED:
  2473.             if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 ||
  2474.                 mouseListener != null) {
  2475.                 return true;
  2476.             }
  2477.             break;
  2478.           case MouseEvent.MOUSE_MOVED:
  2479.           case MouseEvent.MOUSE_DRAGGED:
  2480.             if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 ||
  2481.                 mouseMotionListener != null) {
  2482.                 return true;
  2483.             }
  2484.             break;
  2485.           case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
  2486.           case InputMethodEvent.CARET_POSITION_CHANGED:
  2487.             if ((eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 ||
  2488.                     inputMethodListener != null) {
  2489.                 return true;
  2490.             }
  2491.             break;
  2492.           default:
  2493.             break;
  2494.         }
  2495.         //
  2496.         // Always pass on events defined by external programs.
  2497.         //
  2498.         if (e.id > AWTEvent.RESERVED_ID_MAX) {
  2499.             return true;
  2500.         }
  2501.         return false;
  2502.     }
  2503.  
  2504.     /**
  2505.      * Returns the Window subclass that contains this object. Will
  2506.      * return the object itself, if it is a window.
  2507.      */
  2508.     private Window getWindowForObject(Object obj) {
  2509.     if (obj instanceof Component) {
  2510.         while (obj != null) {
  2511.             if (obj instanceof Window) {
  2512.             return (Window)obj;
  2513.         }
  2514.         obj = ((Component)obj).getParent();
  2515.         }
  2516.         }
  2517.     return null;
  2518.     } // getWindowForObject()
  2519.  
  2520.     /**
  2521.      * @deprecated As of JDK version 1.1,
  2522.      * replaced by dispatchEvent(AWTEvent).
  2523.      */
  2524.     public boolean postEvent(Event e) {
  2525.     ComponentPeer peer = this.peer;
  2526.  
  2527.     if (handleEvent(e)) {
  2528.             e.consume();
  2529.         return true;
  2530.     }
  2531.  
  2532.     Component parent = this.parent;
  2533.     int eventx = e.x;
  2534.     int eventy = e.y;
  2535.     if (parent != null) {
  2536.         e.translate(x, y);
  2537.         if (parent.postEvent(e)) {
  2538.                 e.consume();
  2539.             return true;
  2540.         }
  2541.         // restore coords
  2542.            e.x = eventx;
  2543.         e.y = eventy;
  2544.     }
  2545.     return false;
  2546.     }
  2547.  
  2548.     // Event source interfaces
  2549.  
  2550.     /**
  2551.      * Adds the specified component listener to receive component events from
  2552.      * this component.
  2553.      * If l is null, no exception is thrown and no action is performed.
  2554.      * @param    l   the component listener.
  2555.      * @see      java.awt.event.ComponentEvent
  2556.      * @see      java.awt.event.ComponentListener
  2557.      * @see      java.awt.Component#removeComponentListener
  2558.      * @since    JDK1.1
  2559.      */
  2560.     public synchronized void addComponentListener(ComponentListener l) {
  2561.     if (l == null) {
  2562.         return;
  2563.     }
  2564.         componentListener = AWTEventMulticaster.add(componentListener, l);
  2565.         newEventsOnly = true;
  2566.     }
  2567.     /**
  2568.      * Removes the specified component listener so that it no longer
  2569.      * receives component events from this component. This method performs 
  2570.      * no function, nor does it throw an exception, if the listener 
  2571.      * specified by the argument was not previously added to this component.
  2572.      * If l is null, no exception is thrown and no action is performed.
  2573.      * @param    l   the component listener.
  2574.      * @see      java.awt.event.ComponentEvent
  2575.      * @see      java.awt.event.ComponentListener
  2576.      * @see      java.awt.Component#addComponentListener
  2577.      * @since    JDK1.1
  2578.      */
  2579.     public synchronized void removeComponentListener(ComponentListener l) {
  2580.     if (l == null) {
  2581.         return;
  2582.     }
  2583.         componentListener = AWTEventMulticaster.remove(componentListener, l);
  2584.     }
  2585.  
  2586.     /**
  2587.      * Adds the specified focus listener to receive focus events from
  2588.      * this component when this component gains input focus.
  2589.      * If l is null, no exception is thrown and no action is performed.
  2590.      *
  2591.      * @param    l   the focus listener.
  2592.      * @see      java.awt.event.FocusEvent
  2593.      * @see      java.awt.event.FocusListener
  2594.      * @see      java.awt.Component#removeFocusListener
  2595.      * @since    JDK1.1
  2596.      */
  2597.     public synchronized void addFocusListener(FocusListener l) {
  2598.     if (l == null) {
  2599.         return;
  2600.     }
  2601.         focusListener = AWTEventMulticaster.add(focusListener, l);
  2602.         newEventsOnly = true;
  2603.  
  2604.     // if this is a lightweight component, enable focus events
  2605.     // in the native container.
  2606.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2607.         parent.proxyEnableEvents(AWTEvent.FOCUS_EVENT_MASK);
  2608.     }
  2609.     }
  2610.  
  2611.     /**
  2612.      * Removes the specified focus listener so that it no longer
  2613.      * receives focus events from this component. This method performs 
  2614.      * no function, nor does it throw an exception, if the listener 
  2615.      * specified by the argument was not previously added to this component.
  2616.      * If l is null, no exception is thrown and no action is performed.
  2617.      *
  2618.      * @param    l   the focus listener.
  2619.      * @see      java.awt.event.FocusEvent
  2620.      * @see      java.awt.event.FocusListener
  2621.      * @see      java.awt.Component#addFocusListener
  2622.      * @since    JDK1.1
  2623.      */
  2624.     public synchronized void removeFocusListener(FocusListener l) {
  2625.     if (l == null) {
  2626.         return;
  2627.     }
  2628.         focusListener = AWTEventMulticaster.remove(focusListener, l);
  2629.     }
  2630.  
  2631.     /**
  2632.      * Adds the specified key listener to receive key events from
  2633.      * this component.
  2634.      * If l is null, no exception is thrown and no action is performed.
  2635.      *
  2636.      * @param    l   the key listener.
  2637.      * @see      java.awt.event.KeyEvent
  2638.      * @see      java.awt.event.KeyListener
  2639.      * @see      java.awt.Component#removeKeyListener
  2640.      * @since    JDK1.1
  2641.      */
  2642.     public synchronized void addKeyListener(KeyListener l) {
  2643.     if (l == null) {
  2644.         return;
  2645.     }
  2646.         keyListener = AWTEventMulticaster.add(keyListener, l);
  2647.         newEventsOnly = true;
  2648.  
  2649.     // if this is a lightweight component, enable key events
  2650.     // in the native container.
  2651.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2652.         parent.proxyEnableEvents(AWTEvent.KEY_EVENT_MASK);
  2653.     }
  2654.     }
  2655.  
  2656.     /**
  2657.      * Removes the specified key listener so that it no longer
  2658.      * receives key events from this component. This method performs 
  2659.      * no function, nor does it throw an exception, if the listener 
  2660.      * specified by the argument was not previously added to this component.
  2661.      * If l is null, no exception is thrown and no action is performed.
  2662.      *
  2663.      * @param    l   the key listener.
  2664.      * @see      java.awt.event.KeyEvent
  2665.      * @see      java.awt.event.KeyListener
  2666.      * @see      java.awt.Component#addKeyListener
  2667.      * @since    JDK1.1
  2668.      */
  2669.     public synchronized void removeKeyListener(KeyListener l) {
  2670.     if (l == null) {
  2671.         return;
  2672.     }
  2673.         keyListener = AWTEventMulticaster.remove(keyListener, l);
  2674.     }
  2675.  
  2676.     /**
  2677.      * Adds the specified mouse listener to receive mouse events from
  2678.      * this component.
  2679.      * If l is null, no exception is thrown and no action is performed.
  2680.      *
  2681.      * @param    l   the mouse listener.
  2682.      * @see      java.awt.event.MouseEvent
  2683.      * @see      java.awt.event.MouseListener
  2684.      * @see      java.awt.Component#removeMouseListener
  2685.      * @since    JDK1.1
  2686.      */
  2687.     public synchronized void addMouseListener(MouseListener l) {
  2688.     if (l == null) {
  2689.         return;
  2690.     }
  2691.         mouseListener = AWTEventMulticaster.add(mouseListener,l);
  2692.         newEventsOnly = true;
  2693.  
  2694.     // if this is a lightweight component, enable mouse events
  2695.     // in the native container.
  2696.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2697.         parent.proxyEnableEvents(AWTEvent.MOUSE_EVENT_MASK);
  2698.     }
  2699.     }
  2700.  
  2701.     /**
  2702.      * Removes the specified mouse listener so that it no longer
  2703.      * receives mouse events from this component. This method performs 
  2704.      * no function, nor does it throw an exception, if the listener 
  2705.      * specified by the argument was not previously added to this component.
  2706.      * If l is null, no exception is thrown and no action is performed.
  2707.      *
  2708.      * @param    l   the mouse listener.
  2709.      * @see      java.awt.event.MouseEvent
  2710.      * @see      java.awt.event.MouseListener
  2711.      * @see      java.awt.Component#addMouseListener
  2712.      * @since    JDK1.1
  2713.      */
  2714.     public synchronized void removeMouseListener(MouseListener l) {
  2715.     if (l == null) {
  2716.         return;
  2717.     }
  2718.         mouseListener = AWTEventMulticaster.remove(mouseListener, l);
  2719.     }
  2720.  
  2721.     /**
  2722.      * Adds the specified mouse motion listener to receive mouse motion events from
  2723.      * this component.
  2724.      * If l is null, no exception is thrown and no action is performed.
  2725.      *
  2726.      * @param    l   the mouse motion listener.
  2727.      * @see      java.awt.event.MouseMotionEvent
  2728.      * @see      java.awt.event.MouseMotionListener
  2729.      * @see      java.awt.Component#removeMouseMotionListener
  2730.      * @since    JDK1.1
  2731.      */
  2732.     public synchronized void addMouseMotionListener(MouseMotionListener l) {
  2733.     if (l == null) {
  2734.         return;
  2735.     }
  2736.         mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener,l);
  2737.         newEventsOnly = true;
  2738.  
  2739.     // if this is a lightweight component, enable mouse events
  2740.     // in the native container.
  2741.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2742.         parent.proxyEnableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
  2743.     }
  2744.     }
  2745.  
  2746.     /**
  2747.      * Removes the specified mouse motion listener so that it no longer
  2748.      * receives mouse motion events from this component. This method performs 
  2749.      * no function, nor does it throw an exception, if the listener 
  2750.      * specified by the argument was not previously added to this component.
  2751.      * If l is null, no exception is thrown and no action is performed.
  2752.      *
  2753.      * @param    l   the mouse motion listener.
  2754.      * @see      java.awt.event.MouseMotionEvent
  2755.      * @see      java.awt.event.MouseMotionListener
  2756.      * @see      java.awt.Component#addMouseMotionListener
  2757.      * @since    JDK1.1
  2758.      */
  2759.     public synchronized void removeMouseMotionListener(MouseMotionListener l) {
  2760.     if (l == null) {
  2761.         return;
  2762.     }
  2763.         mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l);
  2764.     }
  2765.  
  2766.     /**
  2767.      * Adds the specified input method listener to receive
  2768.      * input method events from this component. A component will
  2769.      * only receive input method events from input methods
  2770.      * if it also overrides getInputMethodRequests to return an
  2771.      * InputMethodRequests instance.
  2772.      * If l is null, no exception is thrown and no action is performed.
  2773.      *
  2774.      * @param    l   the input method listener.
  2775.      * @see      java.awt.event.InputMethodEvent
  2776.      * @see      java.awt.event.InputMethodListener
  2777.      * @see      java.awt.Component#removeInputMethodListener
  2778.      * @see      java.awt.Component#getInputMethodRequests
  2779.      * @since    JDK1.2
  2780.      */
  2781.     public synchronized void addInputMethodListener(InputMethodListener l) {
  2782.     if (l == null) {
  2783.         return;
  2784.     }
  2785.         inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l);
  2786.         newEventsOnly = true;
  2787.     }
  2788.  
  2789.     /**
  2790.      * Removes the specified input method listener so that it no longer receives
  2791.      * input method events from this component. This method performs 
  2792.      * no function, nor does it throw an exception, if the listener 
  2793.      * specified by the argument was not previously added to this component.
  2794.      * If l is null, no exception is thrown and no action is performed.
  2795.      *
  2796.      * @param    l   the input method listener.
  2797.      * @see      java.awt.event.InputMethodEvent
  2798.      * @see      java.awt.event.InputMethodListener
  2799.      * @see      java.awt.Component#addInputMethodListener
  2800.      * @since    JDK1.2
  2801.      */
  2802.     public synchronized void removeInputMethodListener(InputMethodListener l) {
  2803.     if (l == null) {
  2804.         return;
  2805.     }
  2806.         inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l);
  2807.     }
  2808.  
  2809.     /**
  2810.      * Gets the input method request handler which supports
  2811.      * requests from input methods for this component. A component
  2812.      * that supports on-the-spot text input must override this
  2813.      * method to return an InputMethodRequests instance. At the same
  2814.      * time, it also has to handle input method events.
  2815.      *
  2816.      * @return the input method request handler for this component,
  2817.      * null by default.
  2818.      * @see #addInputMethodListener
  2819.      * @since JDK1.2
  2820.      */
  2821.     public InputMethodRequests getInputMethodRequests() {
  2822.         return null;
  2823.     }
  2824.  
  2825.     /**
  2826.      * Gets the input context used by this component for handling the communication
  2827.      * with input methods when text is entered in this component. By default, the
  2828.      * input context used for the parent component is returned. Components may
  2829.      * override this to return a private input context.
  2830.      *
  2831.      * @return The input context used by this component. Null if no context can
  2832.      * be determined.
  2833.      * @since JDK1.2
  2834.      */
  2835.     public InputContext getInputContext() {
  2836.         Container parent = this.parent;
  2837.         if (parent == null) {
  2838.             return null;
  2839.         } else {
  2840.             return parent.getInputContext();
  2841.         }
  2842.     }
  2843.  
  2844.     /**
  2845.      * Enables the events defined by the specified event mask parameter
  2846.      * to be delivered to this component.
  2847.      * <p>
  2848.      * Event types are automatically enabled when a listener for
  2849.      * that event type is added to the component.
  2850.      * <p>
  2851.      * This method only needs to be invoked by subclasses of
  2852.      * <code>Component</code> which desire to have the specified event
  2853.      * types delivered to <code>processEvent</code> regardless of whether
  2854.      * or not a listener is registered.
  2855.      * @param      eventsToEnable   the event mask defining the event types.
  2856.      * @see        java.awt.Component#processEvent
  2857.      * @see        java.awt.Component#disableEvents
  2858.      * @since      JDK1.1
  2859.      */
  2860.     protected final void enableEvents(long eventsToEnable) {
  2861.         eventMask |= eventsToEnable;
  2862.         newEventsOnly = true;
  2863.  
  2864.     // if this is a lightweight component, enable mouse events
  2865.     // in the native container.
  2866.     if (peer instanceof java.awt.peer.LightweightPeer) {
  2867.         parent.proxyEnableEvents(eventMask);
  2868.     }
  2869.     }
  2870.  
  2871.     /**
  2872.      * Disables the events defined by the specified event mask parameter
  2873.      * from being delivered to this component.
  2874.      * @param      eventsToDisable   the event mask defining the event types
  2875.      * @see        java.awt.Component#enableEvents
  2876.      * @since      JDK1.1
  2877.      */
  2878.     protected final void disableEvents(long eventsToDisable) {
  2879.         eventMask &= ~eventsToDisable;
  2880.     }
  2881.  
  2882.     /**
  2883.      * Potentially coalesce an event being posted with an existing
  2884.      * event.  This method is called by EventQueue.postEvent if an
  2885.      * event with the same ID as the event to be posted is found in
  2886.      * the queue (both events must have this component as their source).
  2887.      * This method either returns a coalesced event which replaces
  2888.      * the existing event (and the new event is then discarded), or
  2889.      * null to indicate that no combining should be done (add the
  2890.      * second event to the end of the queue).  Either event parameter
  2891.      * may be modified and returned, as the other one is discarded
  2892.      * unless null is returned.
  2893.      * <p>
  2894.      * This implementation of coalesceEvents coalesces two event types:
  2895.      * mouse move (and drag) events, and paint (and update) events.
  2896.      * For mouse move events the last event is always returned, causing
  2897.      * intermediate moves to be discarded.  For paint events where the
  2898.      * update rectangles intersect, an event is returned which has an
  2899.      * update rectangle which is the union of the two events.
  2900.      * <p>
  2901.      * Note:  this method must never be synchronized (nor methods it
  2902.      * invokes), as it is called from the underlying native event
  2903.      * code.  Any deadlock with an overwritten version of this method
  2904.      * is the responsibility of the party who overwrote this method!
  2905.      *
  2906.      * @param  existingEvent  the event already on the EventQueue.
  2907.      * @param  newEvent       the event being posted to the EventQueue.
  2908.      * @return a coalesced event, or null indicating that no coalescing
  2909.      *         was done.
  2910.      */
  2911.     protected AWTEvent coalesceEvents(AWTEvent existingEvent,
  2912.                                       AWTEvent newEvent) {
  2913.         int id = existingEvent.getID();
  2914.         if (assert) {
  2915.             // Enable assert to perform this extra sanity check, but it's too
  2916.             // expensive for normal operation.
  2917.             if (id != newEvent.getID() ||
  2918.                 !(existingEvent.getSource().equals(newEvent.getSource()))) {
  2919.                 // Only coalesce events of the same type and source.
  2920.                 return null;
  2921.             }
  2922.         }
  2923.  
  2924.         switch (id) {
  2925.           case Event.MOUSE_MOVE:
  2926.           case Event.MOUSE_DRAG:
  2927.               MouseEvent e = (MouseEvent)existingEvent;
  2928.               if (e.getModifiers() == ((MouseEvent)newEvent).getModifiers()) {
  2929.                   // Just return the newEvent, causing the old to be
  2930.                   // discarded.
  2931.                   return newEvent;
  2932.               }
  2933.               break;
  2934.         }
  2935.         return null;
  2936.     }
  2937.  
  2938.     /**
  2939.      * Processes events occurring on this component. By default this
  2940.      * method calls the appropriate
  2941.      * <code>process<event type>Event</code>
  2942.      * method for the given class of event.
  2943.      * @param     e the event.
  2944.      * @see       java.awt.Component#processComponentEvent
  2945.      * @see       java.awt.Component#processFocusEvent
  2946.      * @see       java.awt.Component#processKeyEvent
  2947.      * @see       java.awt.Component#processMouseEvent
  2948.      * @see       java.awt.Component#processMouseMotionEvent
  2949.      * @see       java.awt.Component#processInputMethodEvent
  2950.      * @since     JDK1.1
  2951.      */
  2952.     protected void processEvent(AWTEvent e) {
  2953.  
  2954.         //System.err.println("Component.processNewEvent:" + e);
  2955.         if (e instanceof FocusEvent) {
  2956.             processFocusEvent((FocusEvent)e);
  2957.  
  2958.         } else if (e instanceof MouseEvent) {
  2959.             switch(e.getID()) {
  2960.               case MouseEvent.MOUSE_PRESSED:
  2961.               case MouseEvent.MOUSE_RELEASED:
  2962.               case MouseEvent.MOUSE_CLICKED:
  2963.               case MouseEvent.MOUSE_ENTERED:
  2964.               case MouseEvent.MOUSE_EXITED:
  2965.                 processMouseEvent((MouseEvent)e);
  2966.                 break;
  2967.               case MouseEvent.MOUSE_MOVED:
  2968.               case MouseEvent.MOUSE_DRAGGED:
  2969.                 processMouseMotionEvent((MouseEvent)e);
  2970.                 break;
  2971.             }
  2972.  
  2973.         } else if (e instanceof KeyEvent) {
  2974.             processKeyEvent((KeyEvent)e);
  2975.  
  2976.         } else if (e instanceof ComponentEvent) {
  2977.             processComponentEvent((ComponentEvent)e);
  2978.         } else if (e instanceof InputMethodEvent) {
  2979.             processInputMethodEvent((InputMethodEvent)e);
  2980.         }
  2981.     }
  2982.  
  2983.     /**
  2984.      * Processes component events occurring on this component by
  2985.      * dispatching them to any registered
  2986.      * <code>ComponentListener</code> objects.
  2987.      * <p>
  2988.      * This method is not called unless component events are
  2989.      * enabled for this component. Component events are enabled
  2990.      * when one of the following occurs:
  2991.      * <p><ul>
  2992.      * <li>A <code>ComponentListener</code> object is registered
  2993.      * via <code>addComponentListener</code>.
  2994.      * <li>Component events are enabled via <code>enableEvents</code>.
  2995.      * </ul>
  2996.      * @param       e the component event.
  2997.      * @see         java.awt.event.ComponentEvent
  2998.      * @see         java.awt.event.ComponentListener
  2999.      * @see         java.awt.Component#addComponentListener
  3000.      * @see         java.awt.Component#enableEvents
  3001.      * @since       JDK1.1
  3002.      */
  3003.     protected void processComponentEvent(ComponentEvent e) {
  3004.     ComponentListener listener = componentListener;
  3005.         if (listener != null) {
  3006.             int id = e.getID();
  3007.             switch(id) {
  3008.               case ComponentEvent.COMPONENT_RESIZED:
  3009.                 listener.componentResized(e);
  3010.                 break;
  3011.               case ComponentEvent.COMPONENT_MOVED:
  3012.                 listener.componentMoved(e);
  3013.                 break;
  3014.               case ComponentEvent.COMPONENT_SHOWN:
  3015.                 listener.componentShown(e);
  3016.                 break;
  3017.               case ComponentEvent.COMPONENT_HIDDEN:
  3018.                 listener.componentHidden(e);
  3019.                 break;
  3020.             }
  3021.         }
  3022.     }
  3023.  
  3024.     /**
  3025.      * Processes focus events occurring on this component by
  3026.      * dispatching them to any registered
  3027.      * <code>FocusListener</code> objects.
  3028.      * <p>
  3029.      * This method is not called unless focus events are
  3030.      * enabled for this component. Focus events are enabled
  3031.      * when one of the following occurs:
  3032.      * <p><ul>
  3033.      * <li>A <code>FocusListener</code> object is registered
  3034.      * via <code>addFocusListener</code>.
  3035.      * <li>Focus events are enabled via <code>enableEvents</code>.
  3036.      * </ul>
  3037.      * @param       e the focus event.
  3038.      * @see         java.awt.event.FocusEvent
  3039.      * @see         java.awt.event.FocusListener
  3040.      * @see         java.awt.Component#addFocusListener
  3041.      * @see         java.awt.Component#enableEvents
  3042.      * @since       JDK1.1
  3043.      */
  3044.     protected void processFocusEvent(FocusEvent e) {
  3045.         FocusListener listener = focusListener;
  3046.         if (listener != null) {
  3047.             int id = e.getID();
  3048.             switch(id) {
  3049.               case FocusEvent.FOCUS_GAINED:
  3050.                 listener.focusGained(e);
  3051.                 break;
  3052.               case FocusEvent.FOCUS_LOST:
  3053.                 listener.focusLost(e);
  3054.                 break;
  3055.             }
  3056.         }
  3057.     }
  3058.  
  3059.     /**
  3060.      * Processes key events occurring on this component by
  3061.      * dispatching them to any registered
  3062.      * <code>KeyListener</code> objects.
  3063.      * <p>
  3064.      * This method is not called unless key events are
  3065.      * enabled for this component. Key events are enabled
  3066.      * when one of the following occurs:
  3067.      * <p><ul>
  3068.      * <li>A <code>KeyListener</code> object is registered
  3069.      * via <code>addKeyListener</code>.
  3070.      * <li>Key events are enabled via <code>enableEvents</code>.
  3071.      * </ul>
  3072.      * @param       e the key event.
  3073.      * @see         java.awt.event.KeyEvent
  3074.      * @see         java.awt.event.KeyListener
  3075.      * @see         java.awt.Component#addKeyListener
  3076.      * @see         java.awt.Component#enableEvents
  3077.      * @since       JDK1.1
  3078.      */
  3079.     protected void processKeyEvent(KeyEvent e) {
  3080.     KeyListener listener = keyListener;
  3081.         if (listener != null) {
  3082.             int id = e.getID();
  3083.             switch(id) {
  3084.               case KeyEvent.KEY_TYPED:
  3085.                 listener.keyTyped(e);
  3086.                 break;
  3087.               case KeyEvent.KEY_PRESSED:
  3088.                 listener.keyPressed(e);
  3089.                 break;
  3090.               case KeyEvent.KEY_RELEASED:
  3091.                 listener.keyReleased(e);
  3092.                 break;
  3093.             }
  3094.         }
  3095.     }
  3096.  
  3097.     /**
  3098.      * Processes mouse events occurring on this component by
  3099.      * dispatching them to any registered
  3100.      * <code>MouseListener</code> objects.
  3101.      * <p>
  3102.      * This method is not called unless mouse events are
  3103.      * enabled for this component. Mouse events are enabled
  3104.      * when one of the following occurs:
  3105.      * <p><ul>
  3106.      * <li>A <code>MouseListener</code> object is registered
  3107.      * via <code>addMouseListener</code>.
  3108.      * <li>Mouse events are enabled via <code>enableEvents</code>.
  3109.      * </ul>
  3110.      * @param       e the mouse event.
  3111.      * @see         java.awt.event.MouseEvent
  3112.      * @see         java.awt.event.MouseListener
  3113.      * @see         java.awt.Component#addMouseListener
  3114.      * @see         java.awt.Component#enableEvents
  3115.      * @since       JDK1.1
  3116.      */
  3117.     protected void processMouseEvent(MouseEvent e) {
  3118.     MouseListener listener = mouseListener;
  3119.         if (listener != null) {
  3120.             int id = e.getID();
  3121.             switch(id) {
  3122.               case MouseEvent.MOUSE_PRESSED:
  3123.                 listener.mousePressed(e);
  3124.                 break;
  3125.               case MouseEvent.MOUSE_RELEASED:
  3126.                 listener.mouseReleased(e);
  3127.                 break;
  3128.               case MouseEvent.MOUSE_CLICKED:
  3129.                 listener.mouseClicked(e);
  3130.                 break;
  3131.               case MouseEvent.MOUSE_EXITED:
  3132.                 listener.mouseExited(e);
  3133.                 break;
  3134.               case MouseEvent.MOUSE_ENTERED:
  3135.                 listener.mouseEntered(e);
  3136.                 break;
  3137.             }
  3138.         }
  3139.     }
  3140.  
  3141.     /**
  3142.      * Processes mouse motion events occurring on this component by
  3143.      * dispatching them to any registered
  3144.      * <code>MouseMotionListener</code> objects.
  3145.      * <p>
  3146.      * This method is not called unless mouse motion events are
  3147.      * enabled for this component. Mouse motion events are enabled
  3148.      * when one of the following occurs:
  3149.      * <p><ul>
  3150.      * <li>A <code>MouseMotionListener</code> object is registered
  3151.      * via <code>addMouseMotionListener</code>.
  3152.      * <li>Mouse motion events are enabled via <code>enableEvents</code>.
  3153.      * </ul>
  3154.      * @param       e the mouse motion event.
  3155.      * @see         java.awt.event.MouseMotionEvent
  3156.      * @see         java.awt.event.MouseMotionListener
  3157.      * @see         java.awt.Component#addMouseMotionListener
  3158.      * @see         java.awt.Component#enableEvents
  3159.      * @since       JDK1.1
  3160.      */
  3161.     protected void processMouseMotionEvent(MouseEvent e) {
  3162.     MouseMotionListener listener = mouseMotionListener;
  3163.         if (listener != null) {
  3164.             int id = e.getID();
  3165.             switch(id) {
  3166.               case MouseEvent.MOUSE_MOVED:
  3167.                 listener.mouseMoved(e);
  3168.                 break;
  3169.               case MouseEvent.MOUSE_DRAGGED:
  3170.                 listener.mouseDragged(e);
  3171.                 break;
  3172.             }
  3173.         }
  3174.     }
  3175.  
  3176.     boolean postsOldMouseEvents() {
  3177.         return false;
  3178.     }
  3179.  
  3180.     /**
  3181.      * Processes input method events occurring on this component by
  3182.      * dispatching them to any registered
  3183.      * <code>InputMethodListener</code> objects.
  3184.      * <p>
  3185.      * This method is not called unless input method events
  3186.      * are enabled for this component. Input method events are enabled
  3187.      * when one of the following occurs:
  3188.      * <p><ul>
  3189.      * <li>An <code>InputMethodListener</code> object is registered
  3190.      * via <code>addInputMethodListener</code>.
  3191.      * <li>Input method events are enabled via <code>enableEvents</code>.
  3192.      * </ul>
  3193.      * @param       e the input method event
  3194.      * @see         java.awt.event.InputMethodEvent
  3195.      * @see         java.awt.event.InputMethodListener
  3196.      * @see         java.awt.Component#addInputMethodListener
  3197.      * @see         java.awt.Component#enableEvents
  3198.      * @since       JDK1.2
  3199.      */
  3200.     protected void processInputMethodEvent(InputMethodEvent e) {
  3201.     InputMethodListener listener = inputMethodListener;
  3202.         if (listener != null) {
  3203.             int id = e.getID();
  3204.             switch (id) {
  3205.               case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
  3206.                 listener.inputMethodTextChanged(e);
  3207.                 break;
  3208.               case InputMethodEvent.CARET_POSITION_CHANGED:
  3209.                 listener.caretPositionChanged(e);
  3210.                 break;
  3211.             }
  3212.         }
  3213.     }
  3214.  
  3215.     /**
  3216.      * @deprecated As of JDK version 1.1
  3217.      * replaced by processEvent(AWTEvent).
  3218.      */
  3219.     public boolean handleEvent(Event evt) {
  3220.     switch (evt.id) {
  3221.       case Event.MOUSE_ENTER:
  3222.         return mouseEnter(evt, evt.x, evt.y);
  3223.  
  3224.       case Event.MOUSE_EXIT:
  3225.         return mouseExit(evt, evt.x, evt.y);
  3226.  
  3227.       case Event.MOUSE_MOVE:
  3228.         return mouseMove(evt, evt.x, evt.y);
  3229.  
  3230.       case Event.MOUSE_DOWN:
  3231.         return mouseDown(evt, evt.x, evt.y);
  3232.  
  3233.       case Event.MOUSE_DRAG:
  3234.         return mouseDrag(evt, evt.x, evt.y);
  3235.  
  3236.       case Event.MOUSE_UP:
  3237.         return mouseUp(evt, evt.x, evt.y);
  3238.  
  3239.       case Event.KEY_PRESS:
  3240.       case Event.KEY_ACTION:
  3241.         return keyDown(evt, evt.key);
  3242.  
  3243.       case Event.KEY_RELEASE:
  3244.       case Event.KEY_ACTION_RELEASE:
  3245.         return keyUp(evt, evt.key);
  3246.  
  3247.       case Event.ACTION_EVENT:
  3248.         return action(evt, evt.arg);
  3249.       case Event.GOT_FOCUS:
  3250.         return gotFocus(evt, evt.arg);
  3251.       case Event.LOST_FOCUS:
  3252.         return lostFocus(evt, evt.arg);
  3253.     }
  3254.         return false;
  3255.     }
  3256.  
  3257.     /**
  3258.      * @deprecated As of JDK version 1.1,
  3259.      * replaced by processMouseEvent(MouseEvent).
  3260.      */
  3261.     public boolean mouseDown(Event evt, int x, int y) {
  3262.     return false;
  3263.     }
  3264.  
  3265.     /**
  3266.      * @deprecated As of JDK version 1.1,
  3267.      * replaced by processMouseMotionEvent(MouseEvent).
  3268.      */
  3269.     public boolean mouseDrag(Event evt, int x, int y) {
  3270.     return false;
  3271.     }
  3272.  
  3273.     /**
  3274.      * @deprecated As of JDK version 1.1,
  3275.      * replaced by processMouseEvent(MouseEvent).
  3276.      */
  3277.     public boolean mouseUp(Event evt, int x, int y) {
  3278.     return false;
  3279.     }
  3280.  
  3281.     /**
  3282.      * @deprecated As of JDK version 1.1,
  3283.      * replaced by processMouseMotionEvent(MouseEvent).
  3284.      */
  3285.     public boolean mouseMove(Event evt, int x, int y) {
  3286.     return false;
  3287.     }
  3288.  
  3289.     /**
  3290.      * @deprecated As of JDK version 1.1,
  3291.      * replaced by processMouseEvent(MouseEvent).
  3292.      */
  3293.     public boolean mouseEnter(Event evt, int x, int y) {
  3294.     return false;
  3295.     }
  3296.  
  3297.     /**
  3298.      * @deprecated As of JDK version 1.1,
  3299.      * replaced by processMouseEvent(MouseEvent).
  3300.      */
  3301.     public boolean mouseExit(Event evt, int x, int y) {
  3302.     return false;
  3303.     }
  3304.  
  3305.     /**
  3306.      * @deprecated As of JDK version 1.1,
  3307.      * replaced by processKeyEvent(KeyEvent).
  3308.      */
  3309.     public boolean keyDown(Event evt, int key) {
  3310.     return false;
  3311.     }
  3312.  
  3313.     /**
  3314.      * @deprecated As of JDK version 1.1,
  3315.      * replaced by processKeyEvent(KeyEvent).
  3316.      */
  3317.     public boolean keyUp(Event evt, int key) {
  3318.     return false;
  3319.     }
  3320.  
  3321.     /**
  3322.      * @deprecated As of JDK version 1.1,
  3323.      * should register this component as ActionListener on component
  3324.      * which fires action events.
  3325.      */
  3326.     public boolean action(Event evt, Object what) {
  3327.     return false;
  3328.     }
  3329.  
  3330.     /**
  3331.      * Makes this Component displayable by connecting it to a
  3332.      * native screen resource.  
  3333.      * This method is called internally by the toolkit and should
  3334.      * not be called directly by programs.
  3335.      * @see       java.awt.Component#isDisplayable
  3336.      * @see       java.awt.Component#removeNotify
  3337.      * @since JDK1.0
  3338.      */
  3339.     public void addNotify() {
  3340.         synchronized (getTreeLock()) {
  3341.         ComponentPeer peer = this.peer;
  3342.         if (peer == null || peer instanceof java.awt.peer.LightweightPeer){
  3343.             if (peer == null) {
  3344.             // Update both the Component's peer variable and the local
  3345.           // variable we use for thread safety.
  3346.           this.peer = peer = getToolkit().createComponent(this);
  3347.         }
  3348.  
  3349.         // This is a lightweight component which means it won't be
  3350.         // able to get window-related events by itself.  If any
  3351.         // have been enabled, then the nearest native container must
  3352.         // be enabled.
  3353.         long mask = 0;
  3354.         if ((mouseListener != null) || ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0)) {
  3355.             mask |= AWTEvent.MOUSE_EVENT_MASK;
  3356.         }
  3357.         if ((mouseMotionListener != null) ||
  3358.             ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0)) {
  3359.             mask |= AWTEvent.MOUSE_MOTION_EVENT_MASK;
  3360.         }
  3361.         if (focusListener != null || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
  3362.             mask |= AWTEvent.FOCUS_EVENT_MASK;
  3363.         }
  3364.         if (keyListener != null || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0) {
  3365.             mask |= AWTEvent.KEY_EVENT_MASK;
  3366.         }
  3367.         if (mask != 0) {
  3368.             parent.proxyEnableEvents(mask);
  3369.         }
  3370.         } else {
  3371.             // It's native.  If the parent is lightweight it
  3372.             // will need some help.
  3373.             Container parent = this.parent;
  3374.         if (parent != null && parent.peer instanceof java.awt.peer.LightweightPeer) {
  3375.             new NativeInLightFixer();
  3376.         }
  3377.         }
  3378.         invalidate();
  3379.  
  3380.         int npopups = (popups != null? popups.size() : 0);
  3381.         for (int i = 0 ; i < npopups ; i++) {
  3382.             PopupMenu popup = (PopupMenu)popups.elementAt(i);
  3383.         popup.addNotify();
  3384.         }
  3385.         for (Component p = getParent(); p != null; p = p.getParent())
  3386.                 if (p instanceof Window) {
  3387.             if (((Window)p).getWarningString() == null) {
  3388.                 //!CQ set newEventsOnly if appropriate/possible?
  3389.             }
  3390.             break;
  3391.         }
  3392.         
  3393.         if (dropTarget != null) dropTarget.addNotify(peer);
  3394.  
  3395.         peerFont = getFont();
  3396.     }
  3397.     }
  3398.  
  3399.     /** 
  3400.      * Makes this Component undisplayable by destroying it native
  3401.      * screen resource. 
  3402.      * This method is called by the toolkit internally and should
  3403.      * not be called directly by programs.
  3404.      * @see       java.awt.Component#isDisplayable
  3405.      * @see       java.awt.Component#addNotify
  3406.      * @since JDK1.0
  3407.      */
  3408.     public void removeNotify() {
  3409.         synchronized (getTreeLock()) {
  3410.         int npopups = (popups != null? popups.size() : 0);
  3411.         for (int i = 0 ; i < npopups ; i++) {
  3412.             PopupMenu popup = (PopupMenu)popups.elementAt(i);
  3413.         popup.removeNotify();
  3414.         }
  3415.         // If there is any input context for this component, notify
  3416.         // that this component is being removed. (This has to be done
  3417.         // before hiding peer.)
  3418.         if (areInputMethodsEnabled()) {
  3419.             InputContext inputContext = getInputContext();
  3420.         if (inputContext != null) {
  3421.             inputContext.removeNotify(this);
  3422.         }
  3423.         }
  3424.  
  3425.         ComponentPeer p = peer;
  3426.         if (p != null) {
  3427.  
  3428.             if (dropTarget != null) dropTarget.removeNotify(peer);
  3429.  
  3430.         // Hide peer first to stop system events such as cursor moves.
  3431.         if (visible) {
  3432.             p.hide();
  3433.         }
  3434.  
  3435.         peer = null; // Stop peer updates.
  3436.         peerFont = null;
  3437.  
  3438.         Toolkit.getEventQueue().removeSourceEvents(this);
  3439.  
  3440.  
  3441.         p.dispose();
  3442.         }
  3443.     }
  3444.     }
  3445.  
  3446.     /**
  3447.      * @deprecated As of JDK version 1.1,
  3448.      * replaced by processFocusEvent(FocusEvent).
  3449.      */
  3450.     public boolean gotFocus(Event evt, Object what) {
  3451.     return false;
  3452.     }
  3453.  
  3454.     /**
  3455.      * @deprecated As of JDK version 1.1,
  3456.      * replaced by processFocusEvent(FocusEvent).
  3457.      */
  3458.     public boolean lostFocus(Event evt, Object what) {
  3459.     return false;
  3460.     }
  3461.  
  3462.     /**
  3463.      * Returns the value of a flag that indicates whether
  3464.      * this component can be traversed using
  3465.      * Tab or Shift-Tab keyboard focus traversal.  If this method
  3466.      * returns "false", this component may still request the keyboard
  3467.      * focus using <code>requestFocus()</code>, but it will not automatically
  3468.      * be assigned focus during tab traversal.
  3469.      * @return    <code>true</code> if this component is
  3470.      *            focus-traverable; <code>false</code> otherwise.
  3471.      * @since     JDK1.1
  3472.      */
  3473.     public boolean isFocusTraversable() {
  3474.         ComponentPeer peer = this.peer;
  3475.     if (peer != null) {
  3476.         return peer.isFocusTraversable();
  3477.     }
  3478.     return false;
  3479.     }
  3480.  
  3481.     /**
  3482.      * Requests that this component get the input focus.
  3483.      * The component must be visible
  3484.      * on the screen for this request to be granted
  3485.      * @see FocusEvent
  3486.      * @see #addFocusListener
  3487.      * @see #processFocusEvent
  3488.      * @see #isFocusTraversable
  3489.      * @since JDK1.0
  3490.      */
  3491.     public void requestFocus() {
  3492.         ComponentPeer peer = this.peer;
  3493.     if (peer != null) {
  3494.         if (peer instanceof java.awt.peer.LightweightPeer) {
  3495.         parent.proxyRequestFocus(this);
  3496.         } else {
  3497.         peer.requestFocus();
  3498.                 Toolkit.getEventQueue().changeKeyEventFocus(this);
  3499.         }
  3500.     }
  3501.     }
  3502.  
  3503.     /**
  3504.      * Transfers the focus to the next component.
  3505.      * @see       java.awt.Component#requestFocus
  3506.      * @since     JDK1.1s
  3507.      */
  3508.      public void transferFocus() {
  3509.         nextFocus();
  3510.      }
  3511.  
  3512.     /**
  3513.      * @deprecated As of JDK version 1.1,
  3514.      * replaced by transferFocus().
  3515.      */
  3516.      public void nextFocus() {
  3517.         Container parent = this.parent;
  3518.     if (parent != null) {
  3519.         parent.transferFocus(this);
  3520.     }
  3521.      }
  3522.  
  3523.     /**
  3524.      * Returns true if this Component has the keyboard focus.
  3525.      *
  3526.      * @return true if this Component has the keyboard focus.
  3527.      * @since JDK1.2
  3528.      */
  3529.     public boolean hasFocus() {
  3530.     if ((eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) {
  3531.         return hasFocus;
  3532.     }
  3533.     else {
  3534.         for (Container p = getParent(); p != null; p = p.getParent()) {
  3535.         if (p instanceof Window) {
  3536.             return ((Window)p).getFocusOwner() == this;
  3537.         }
  3538.         }
  3539.         return false;
  3540.     }
  3541.     }
  3542.  
  3543.     /**
  3544.      * Adds the specified popup menu to the component.
  3545.      * @param     popup the popup menu to be added to the component.
  3546.      * @see       java.awt.Component#remove(java.awt.MenuComponent)
  3547.      * @since     JDK1.1
  3548.      */
  3549.     public synchronized void add(PopupMenu popup) {
  3550.     if (popup.parent != null) {
  3551.         popup.parent.remove(popup);
  3552.     }
  3553.         if (popups == null) {
  3554.             popups = new Vector();
  3555.         }
  3556.     popups.addElement(popup);
  3557.     popup.parent = this;
  3558.  
  3559.     if (peer != null) {
  3560.         if (popup.peer == null) {
  3561.         popup.addNotify();
  3562.         }
  3563.     }
  3564.     }
  3565.  
  3566.     /**
  3567.      * Removes the specified popup menu from the component.
  3568.      * @param     popup the popup menu to be removed.
  3569.      * @see       java.awt.Component#add(java.awt.PopupMenu)
  3570.      * @since     JDK1.1
  3571.      */
  3572.     public synchronized void remove(MenuComponent popup) {
  3573.         if (popups != null) {
  3574.         int index = popups.indexOf(popup);
  3575.         if (index >= 0) {
  3576.             PopupMenu pmenu = (PopupMenu)popup;
  3577.             if (pmenu.peer != null) {
  3578.             pmenu.removeNotify();
  3579.         }
  3580.         pmenu.parent = null;
  3581.         popups.removeElementAt(index);
  3582.         if (popups.size() == 0) {
  3583.             popups = null;
  3584.         }
  3585.         }
  3586.     }
  3587.     }
  3588.  
  3589.     /**
  3590.      * Returns a string representing the state of this component. This 
  3591.      * method is intended to be used only for debugging purposes, and the 
  3592.      * content and format of the returned string may vary between 
  3593.      * implementations. The returned string may be empty but may not be 
  3594.      * <code>null</code>.
  3595.      * 
  3596.      * @return  a string representation of this component's state.
  3597.      * @since     JDK1.0
  3598.      */
  3599.     protected String paramString() {
  3600.         String thisName = getName();
  3601.     String str = (thisName != null? thisName : "") + "," + x + "," + y + "," + width + "x" + height;
  3602.     if (!valid) {
  3603.         str += ",invalid";
  3604.     }
  3605.     if (!visible) {
  3606.         str += ",hidden";
  3607.     }
  3608.     if (!enabled) {
  3609.         str += ",disabled";
  3610.     }
  3611.     return str;
  3612.     }
  3613.  
  3614.     /**
  3615.      * Returns a string representation of this component and its values.
  3616.      * @return    a string representation of this component.
  3617.      * @since     JDK1.0
  3618.      */
  3619.     public String toString() {
  3620.     return getClass().getName() + "[" + paramString() + "]";
  3621.     }
  3622.  
  3623.     /**
  3624.      * Prints a listing of this component to the standard system output
  3625.      * stream <code>System.out</code>.
  3626.      * @see       java.lang.System#out
  3627.      * @since     JDK1.0
  3628.      */
  3629.     public void list() {
  3630.     list(System.out, 0);
  3631.     }
  3632.  
  3633.     /**
  3634.      * Prints a listing of this component to the specified output
  3635.      * stream.
  3636.      * @param    out   a print stream.
  3637.      * @since    JDK1.0
  3638.      */
  3639.     public void list(PrintStream out) {
  3640.     list(out, 0);
  3641.     }
  3642.  
  3643.     /**
  3644.      * Prints out a list, starting at the specified indention, to the
  3645.      * specified print stream.
  3646.      * @param     out      a print stream.
  3647.      * @param     indent   number of spaces to indent.
  3648.      * @see       java.io.PrintStream#println(java.lang.Object)
  3649.      * @since     JDK1.0
  3650.      */
  3651.     public void list(PrintStream out, int indent) {
  3652.     for (int i = 0 ; i < indent ; i++) {
  3653.         out.print("  ");
  3654.     }
  3655.     out.println(this);
  3656.     }
  3657.  
  3658.     /**
  3659.      * Prints a listing to the specified print writer.
  3660.      * @param  out  The print writer to print to.
  3661.      * @since JDK1.1
  3662.      */
  3663.     public void list(PrintWriter out) {
  3664.     list(out, 0);
  3665.     }
  3666.  
  3667.     /**
  3668.      * Prints out a list, starting at the specified indention, to
  3669.      * the specified print writer.
  3670.      * @param out The print writer to print to.
  3671.      * @param indent The number of spaces to indent.
  3672.      * @see       java.io.PrintStream#println(java.lang.Object)
  3673.      * @since JDK1.1
  3674.      */
  3675.     public void list(PrintWriter out, int indent) {
  3676.     for (int i = 0 ; i < indent ; i++) {
  3677.         out.print("  ");
  3678.     }
  3679.     out.println(this);
  3680.     }
  3681.  
  3682.     /*
  3683.      * Fetch the native container somewhere higher up in the component
  3684.      * tree that contains this component.
  3685.      */
  3686.     Container getNativeContainer() {
  3687.     Container p = parent;
  3688.     while (p != null && p.peer instanceof java.awt.peer.LightweightPeer) {
  3689.         p = p.getParent();
  3690.     }
  3691.     return p;
  3692.     }
  3693.  
  3694.     /**
  3695.      * Add a PropertyChangeListener to the listener list.
  3696.      * The listener is registered for all properties.
  3697.      * <p>
  3698.      * A PropertyChangeEvent will get fired in response to an
  3699.      * explicit setFont, setBackground, or SetForeground on the
  3700.      * current component.  Note that if the current component is
  3701.      * inheriting its foreground, background, or font from its
  3702.      * container, then no event will be fired in response to a
  3703.      * change in the inherited property.
  3704.      *
  3705.      * If listener is null, no exception is thrown and no action is performed.
  3706.      *
  3707.      * @param    listener  The PropertyChangeListener to be added
  3708.      */
  3709.     public synchronized void addPropertyChangeListener(
  3710.                 PropertyChangeListener listener) {
  3711.     if (listener == null) {
  3712.         return;
  3713.     }
  3714.     if (changeSupport == null) {
  3715.         changeSupport = new java.beans.PropertyChangeSupport(this);
  3716.     }
  3717.     changeSupport.addPropertyChangeListener(listener);
  3718.     }
  3719.  
  3720.     /**
  3721.      * Remove a PropertyChangeListener from the listener list.
  3722.      * This removes a PropertyChangeListener that was registered
  3723.      * for all properties.
  3724.      *
  3725.      * If listener is null, no exception is thrown and no action is performed.
  3726.      *
  3727.      * @param listener  The PropertyChangeListener to be removed
  3728.      */
  3729.     public synchronized void removePropertyChangeListener(
  3730.                 PropertyChangeListener listener) {
  3731.     if (listener == null) {
  3732.         return;
  3733.     }
  3734.     if (changeSupport == null) {
  3735.         return;
  3736.     }
  3737.     changeSupport.removePropertyChangeListener(listener);
  3738.     }
  3739.  
  3740.     /**
  3741.      * Add a PropertyChangeListener for a specific property.  The listener
  3742.      * will be invoked only when a call on firePropertyChange names that
  3743.      * specific property.
  3744.      *
  3745.      * If listener is null, no exception is thrown and no action is performed.
  3746.      *
  3747.      * @param propertyName  The name of the property to listen on.
  3748.      * @param listener  The PropertyChangeListener to be added
  3749.      */
  3750.     public synchronized void addPropertyChangeListener(
  3751.                 String propertyName,
  3752.                 PropertyChangeListener listener) {
  3753.     if (listener == null) {
  3754.         return;
  3755.     }
  3756.     if (changeSupport == null) {
  3757.         changeSupport = new java.beans.PropertyChangeSupport(this);
  3758.     }
  3759.     changeSupport.addPropertyChangeListener(propertyName, listener);
  3760.     }
  3761.  
  3762.     /**
  3763.      * Remove a PropertyChangeListener for a specific property.
  3764.      * If listener is null, no exception is thrown and no action is performed.
  3765.      *
  3766.      * @param propertyName  The name of the property that was listened on.
  3767.      * @param listener  The PropertyChangeListener to be removed
  3768.      */
  3769.     public synchronized void removePropertyChangeListener(
  3770.                 String propertyName,
  3771.                 PropertyChangeListener listener) {
  3772.     if (listener == null) {
  3773.         return;
  3774.     }
  3775.     if (changeSupport == null) {
  3776.         return;
  3777.     }
  3778.     changeSupport.removePropertyChangeListener(propertyName, listener);
  3779.     }
  3780.  
  3781.     /**
  3782.      * Support for reporting bound property changes.  This method can be called
  3783.      * when a bound property has changed and it will send the appropriate
  3784.      * PropertyChangeEvent to any registered PropertyChangeListeners.
  3785.      */
  3786.     protected void firePropertyChange(String propertyName,
  3787.                     Object oldValue, Object newValue) {
  3788.         java.beans.PropertyChangeSupport changeSupport = this.changeSupport;
  3789.     if (changeSupport == null) {
  3790.         return;
  3791.     }
  3792.     changeSupport.firePropertyChange(propertyName, oldValue, newValue);
  3793.     }
  3794.  
  3795.  
  3796.     /* Serialization support.
  3797.      */
  3798.     /**
  3799.      * Component Serialized Data Version.
  3800.      *
  3801.      * @serial
  3802.      */
  3803.     private int componentSerializedDataVersion = 2;
  3804.  
  3805.     /**
  3806.      * Writes default serializable fields to stream.  Writes
  3807.      * a list of serializable ItemListener(s) as optional data.
  3808.      * The non-serializable ItemListener(s) are detected and
  3809.      * no attempt is made to serialize them.
  3810.      *
  3811.      * @serialData Null terminated sequence of 0 or more pairs.
  3812.      *             The pair consists of a String and Object.
  3813.      *             The String indicates the type of object and
  3814.      *             is one of the following :
  3815.      *             itemListenerK indicating and ItemListener object.
  3816.      *
  3817.      * @see AWTEventMulticaster.save(ObjectOutputStream, String, EventListener)
  3818.      * @see java.awt.Component.itemListenerK
  3819.      */
  3820.     private void writeObject(ObjectOutputStream s)
  3821.         throws IOException
  3822.     {
  3823.       s.defaultWriteObject();
  3824.  
  3825.       AWTEventMulticaster.save(s, componentListenerK, componentListener);
  3826.       AWTEventMulticaster.save(s, focusListenerK, focusListener);
  3827.       AWTEventMulticaster.save(s, keyListenerK, keyListener);
  3828.       AWTEventMulticaster.save(s, mouseListenerK, mouseListener);
  3829.       AWTEventMulticaster.save(s, mouseMotionListenerK, mouseMotionListener);
  3830.       AWTEventMulticaster.save(s, inputMethodListenerK, inputMethodListener);
  3831.  
  3832.       s.writeObject(null);
  3833.       s.writeObject(componentOrientation);
  3834.     }
  3835.  
  3836.     /**
  3837.      * Read the ObjectInputStream and if it isnt null
  3838.      * add a listener to receive item events fired
  3839.      * by the components.
  3840.      * Unrecognised keys or values will be Ignored.
  3841.      *
  3842.      * @see removeActionListener()
  3843.      * @see addActionListener()
  3844.      */
  3845.     private void readObject(ObjectInputStream s)
  3846.         throws ClassNotFoundException, IOException
  3847.     {
  3848.         s.defaultReadObject();
  3849.  
  3850.     appContext = AppContext.getAppContext();
  3851.     SunToolkit.insertTargetMapping(this, appContext);
  3852.  
  3853.         Object keyOrNull;
  3854.         while(null != (keyOrNull = s.readObject())) {
  3855.         String key = ((String)keyOrNull).intern();
  3856.  
  3857.         if (componentListenerK == key)
  3858.             addComponentListener((ComponentListener)(s.readObject()));
  3859.  
  3860.         else if (focusListenerK == key)
  3861.             addFocusListener((FocusListener)(s.readObject()));
  3862.  
  3863.         else if (keyListenerK == key)
  3864.             addKeyListener((KeyListener)(s.readObject()));
  3865.  
  3866.         else if (mouseListenerK == key)
  3867.             addMouseListener((MouseListener)(s.readObject()));
  3868.  
  3869.         else if (mouseMotionListenerK == key)
  3870.             addMouseMotionListener((MouseMotionListener)(s.readObject()));
  3871.  
  3872.         else if (inputMethodListenerK == key)
  3873.             addInputMethodListener((InputMethodListener)(s.readObject()));
  3874.  
  3875.         else // skip value for unrecognized key
  3876.             s.readObject();
  3877.  
  3878.         }
  3879.         
  3880.         // Read the component's orientation if it's present
  3881.         Object orient = null;
  3882.  
  3883.         try {
  3884.             orient = s.readObject();
  3885.         } catch (java.io.OptionalDataException e) {
  3886.             // JDK 1.1 instances will not have this optional data.
  3887.             // e.eof will be true to indicate that there is no more
  3888.             // data available for this object.
  3889.         // If e.eof is not true, throw the exception as it
  3890.         // might have been caused by reasons unrelated to 
  3891.         // componentOrientation.
  3892.         
  3893.         if (!e.eof)  {
  3894.         throw (e);
  3895.         }
  3896.         }
  3897.  
  3898.         if (orient != null) {
  3899.             componentOrientation = (ComponentOrientation)orient;
  3900.         } else {
  3901.             componentOrientation = ComponentOrientation.UNKNOWN;
  3902.         }
  3903.  
  3904.     if (popups != null) {
  3905.         int npopups = popups.size();
  3906.         for (int i = 0 ; i < npopups ; i++) {
  3907.         PopupMenu popup = (PopupMenu)popups.elementAt(i);
  3908.         popup.parent = this;
  3909.         }
  3910.     }
  3911.     }
  3912.     
  3913.     /**
  3914.      * Set the language-sensitive orientation that is to be used to order
  3915.      * the elements or text within this component.  Language-sensitive
  3916.      * LayoutManager and Component subclasses will use this property to
  3917.      * determine how to lay out and draw components.
  3918.      * <p>
  3919.      * At construction time, a component's orientation is set to
  3920.      * ComponentOrientation.UNKNOWN, indicating that it has not been specified
  3921.      * explicitly.  The UNKNOWN orientation behaves the same as
  3922.      * ComponentOrientation.LEFT_TO_RIGHT.
  3923.      * <p>
  3924.      * To set the orientation of a single component, use this method.
  3925.      * To apply a ResourceBundle's orientation to an entire component
  3926.      * hierarchy, use java.awt.Window.applyResourceBundle.
  3927.      *
  3928.      * @see java.awt.ComponentOrientation
  3929.      * @see java.awt.Window#ApplyResourceBundle(java.util.ResourceBundle)
  3930.      *
  3931.      * @author Laura Werner, IBM
  3932.      */
  3933.     public void setComponentOrientation(ComponentOrientation o) {
  3934.         componentOrientation = o;
  3935.  
  3936.     // This could change the preferred size of the Component.
  3937.     if (valid) {
  3938.         invalidate();
  3939.     }
  3940.     }
  3941.  
  3942.     /**
  3943.      * Retrieve the language-sensitive orientation that is to be used to order
  3944.      * the elements or text within this component.  LayoutManager and Component
  3945.      * subclasses that wish to respect orientation should call this method to
  3946.      * get the component's orientation before performing layout or drawing.
  3947.      *
  3948.      * @see java.awt.ComponentOrientation
  3949.      *
  3950.      * @author Laura Werner, IBM
  3951.      */
  3952.     public ComponentOrientation getComponentOrientation() {
  3953.         return componentOrientation;
  3954.     }
  3955.  
  3956.  
  3957.     /**
  3958.      * This odd class is to help out a native component that has been
  3959.      * embedded in a lightweight component.  Moving lightweight
  3960.      * components around and changing their visibility is not seen
  3961.      * by the native window system.  This is a feature for lightweights,
  3962.      * but a problem for native components that depend upon the
  3963.      * lightweights.  An instance of this class listens to the lightweight
  3964.      * parents of an associated native component (the outer class).
  3965.      *
  3966.      * @author  Timothy Prinzing
  3967.      */
  3968.     private final class NativeInLightFixer implements ComponentListener, ContainerListener {
  3969.  
  3970.     NativeInLightFixer() {
  3971.         lightParents = new Vector();
  3972.         Container p = parent;
  3973.         // stash a reference to the components that are being observed so that
  3974.         // we can reliably remove ourself as a listener later.
  3975.         for (; p.peer instanceof java.awt.peer.LightweightPeer; p = p.parent) {
  3976.  
  3977.         // register listeners and stash a reference
  3978.         p.addComponentListener(this);
  3979.         p.addContainerListener(this);
  3980.         lightParents.addElement(p);
  3981.         }
  3982.         // register with the native host (native parent of associated native)
  3983.         // to get notified if the top-level lightweight is removed.
  3984.         nativeHost = p;
  3985.         p.addContainerListener(this);
  3986.  
  3987.         // kick start the fixup.  Since the event isn't looked at
  3988.         // we can simulate movement notification.
  3989.         componentMoved(null);
  3990.     }
  3991.  
  3992.     // --- ComponentListener -------------------------------------------
  3993.  
  3994.     /**
  3995.      * Invoked when one of the lightweight parents has been resized.
  3996.      * This doesn't change the position of the native child so it
  3997.      * is ignored.
  3998.      */
  3999.         public void componentResized(ComponentEvent e) {
  4000.     }
  4001.  
  4002.     /**
  4003.      * Invoked when one of the lightweight parents has been moved.
  4004.      * The native peer must be told of the new position which is
  4005.      * relative to the native container that is hosting the
  4006.      * lightweight components.
  4007.      */
  4008.         public void componentMoved(ComponentEvent e) {
  4009.         synchronized (getTreeLock()) {
  4010.         int nativeX = x;
  4011.         int nativeY = y;
  4012.         for(Component c = parent; (c != null) &&
  4013.             (c.peer instanceof java.awt.peer.LightweightPeer);
  4014.             c = c.parent) {
  4015.  
  4016.             nativeX += c.x;
  4017.             nativeY += c.y;
  4018.         }
  4019.         if (peer != null) {
  4020.             peer.setBounds(nativeX, nativeY, width, height);
  4021.         }
  4022.         }
  4023.     }
  4024.  
  4025.     /**
  4026.      * Invoked when a lightweight parent component has been
  4027.      * shown.  The associated native component must also be
  4028.      * shown if it hasn't had an overriding hide done on it.
  4029.      */
  4030.         public void componentShown(ComponentEvent e) {
  4031.         if (isShowing()) {
  4032.         synchronized (getTreeLock()) {
  4033.             if (peer != null) {
  4034.             peer.show();
  4035.             }
  4036.         }
  4037.         }
  4038.     }
  4039.  
  4040.     /**
  4041.      * Invoked when component has been hidden.
  4042.      */
  4043.         public void componentHidden(ComponentEvent e) {
  4044.         if (visible) {
  4045.         synchronized (getTreeLock()) {
  4046.             if (peer != null) {
  4047.             peer.hide();
  4048.             }
  4049.         }
  4050.         }
  4051.     }
  4052.  
  4053.     // --- ContainerListener ------------------------------------
  4054.  
  4055.     /**
  4056.      * Invoked when a component has been added to a lightweight
  4057.      * parent.  This doesn't effect the native component.
  4058.      */
  4059.         public void componentAdded(ContainerEvent e) {
  4060.     }
  4061.  
  4062.     /**
  4063.      * Invoked when a lightweight parent has been removed.
  4064.      * This means the services of this listener are no longer
  4065.      * required and it should remove all references (ie
  4066.      * registered listeners).
  4067.      */
  4068.         public void componentRemoved(ContainerEvent e) {
  4069.         Component c = e.getChild();
  4070.         if (c == Component.this) {
  4071.         removeReferences();
  4072.         } else {
  4073.         int n = lightParents.size();
  4074.         for (int i = 0; i < n; i++) {
  4075.             Container p = (Container) lightParents.elementAt(i);
  4076.             if (p == c) {
  4077.             removeReferences();
  4078.             break;
  4079.             }
  4080.         }
  4081.         }
  4082.     }
  4083.  
  4084.     /**
  4085.      * Remove references to this object so it can be
  4086.      * garbage collected.
  4087.      */
  4088.     void removeReferences() {
  4089.         int n = lightParents.size();
  4090.         for (int i = 0; i < n; i++) {
  4091.         Container c = (Container) lightParents.elementAt(i);
  4092.         c.removeComponentListener(this);
  4093.         c.removeContainerListener(this);
  4094.         }
  4095.         nativeHost.removeContainerListener(this);
  4096.     }
  4097.  
  4098.     Vector lightParents;
  4099.     Container nativeHost;
  4100.     }
  4101.  
  4102.     /**
  4103.      * Initialize JNI field and method IDs
  4104.      */
  4105.     private static native void initIDs();
  4106.  
  4107. }
  4108.